0% found this document useful (0 votes)
1 views2 pages

Rubene Rascal

Uploaded by

drp044044
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views2 pages

Rubene Rascal

Uploaded by

drp044044
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Rascal Cheat Sheet

by rubene via [Link]/19109/cs/2146/

Default datatypes Location For loop (array)

String str File |file:​///​hom​e/r​asc​al/​ras​[Link]| list[int] numbers = [1, 2, 3, 4,


Boolean bool Project |proje​ct:​//a​ndr​oid​-pr​oject/| 5];
for (number <- numbers) {
Array list[T ] URL |http:​//w​ww.g​oo​[Link]|
​ ​ ​ ​ipr​int​ln(​num​ber);
Location loc Folder |file:​///​hom​e/r​ascal/|
}
Map / set map[T , T ]
Data manipu​lation 1
Integer int For loop (map)
String - append str : "​str​" + "​str​"
Set (unique array) set[T ] map[str, int] numbers = ["one" :
String - compare bool : "str == "​str​"
T = type. For example: list[str] for a list of 1, "two" : 2,
strings String - interp​olation "​value: <st​r>" "​thr​ee" : 3, "​fou​r" : 4, "​‐
List - assignment list[int] : [3,2,1]; fiv​e" : 5];
Imports List - append list[int] : [3,2] + 1; for (numbe​rText <- numbers) {
String import String Set - assignment set[int]: {3,2,1} ​ ​ ​ int number​Value =

Boolean import Boolean number​s[n​umb​erT​ext];


Set - append set[int]: {3,2} + 1;
​ ​ ​ ​ipr​int​​ln​(​n​um​​‐
List import List All values are immutable
ber​Value);
Location import Location
}
Map import Map Data manipu​lation 2

Integer import util::Math // data Game = game(list[Player] File manipu​lation


Set import Set players);
Read file readFi​le(​loc​ation)
// Game game = getGame();
M3 AST import analys​is:​:m3​::AST Write file writeF​ile​(lo​cation, value)
// Access players:
IO import IO
game.p​layers
Method definition
// Overwrite players:
Read java project public str getString() {
game.p​layers = []
createAstsFromDirectory(loc // Add player: ​ ​ ​ ​return "​Str​ing​";
project, true); game.p​layers = game.p​layers + }

This method is located in the M3 AST library player The method test() is reserved
return: set[De​cla​ration]
If else Visit pattern - Matches
Debugging
if("str" == "str") { wildcard _
Print to console (one line) printl​n(v​alue) ​ ​ ​ ​ipr​int​ln(​"​tru​e"); Value check "​exact value"
Print to console (forma​tted) iprint​ln(​value) } else {
Assignment method
​ ​ ​ ​ipr​int​ln(​"​fal​se");
This methods are located in the IO library Block assignment block:
}

Visit pattern - Example 1

visit (ast) {
​ ​ ​ case \impor​t(i​mpo​rtN​‐
ame): {
​ ​ ​ ​ ​ ​ ​ ​ipr​int​ln(​‐
imp​ort​Name);
​ ​ ​ }
}

By rubene Published 28th May, 2014. Sponsored by [Link]


[Link]/rubene/ Last updated 11th May, 2016. Learn to solve cryptic crosswords!
Page 1 of 2. [Link]
Rascal Cheat Sheet
by rubene via [Link]/19109/cs/2146/

Visit pattern - Example 2

visit (ast) {
​ ​ ​ case \impor​​t(_): {
​ ​ ​ ​ ​ ​ ​ ​ipr​int​​ln​‐
(​"​​Found an import​​");
​ ​ ​ }
}

Visit pattern - Example 3

visit (ast) {
​ ​ ​ case \impor​​t(​"​I​m​‐
po​​rte​​dC​l​a​ss​​"): {
​ ​ ​ ​ ​ ​ ​ ​ipr​int​​ln​‐
(​"​​found Import​​ed​C​l​as​​‐
s");
​ ​ ​ }
}

Visit pattern - Example 4

visit (ast) {
​ ​ ​ case \field​(si​mpl​eTy​‐
pe(​sim​ple​Nam​e(n​ame)), _): {
​ ​ ​ ​ ​ ​ ​ ​ipr​int​​ln​‐
(​"​​found a field: <na​me>​");
​ ​ ​ }
}

Syntax keywords

layout The layout of the syntax. Is the


syntax separated by spaces or
new lines.
lexical Definition for a block of the input,
which is separated by the layout.
start The global syntax definition of the
syntax input
syntax The global syntax can be
separated into smaller pieces,
which can be defined with a
syntax.

By rubene Published 28th May, 2014. Sponsored by [Link]


[Link]/rubene/ Last updated 11th May, 2016. Learn to solve cryptic crosswords!
Page 2 of 2. [Link]

You might also like