Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Metaprogramming/Rascal/metaprogramming-1.rascal
Normal file
14
Task/Metaprogramming/Rascal/metaprogramming-1.rascal
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
extend ViewParseTree;
|
||||
|
||||
layout Whitespace = [\ \t\n]*;
|
||||
syntax A = "a";
|
||||
syntax B = "b";
|
||||
start syntax C = "c" | A C B;
|
||||
|
||||
layout Whitespace = [\ \t\n]*;
|
||||
lexical Integer = [0-9]+;
|
||||
start syntax E1 = Integer
|
||||
| E "*" E
|
||||
> E "+" E
|
||||
| "(" E ")"
|
||||
;
|
||||
9
Task/Metaprogramming/Rascal/metaprogramming-2.rascal
Normal file
9
Task/Metaprogramming/Rascal/metaprogramming-2.rascal
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
map[str, int] operatorUsage(PROGRAM P) {
|
||||
m = ();
|
||||
visit(P){
|
||||
case add(_,_): m["add"] ? 0 += 1;
|
||||
case sub(_,_): m["sub"] ? 0 += 1;
|
||||
case conc(_,_): m["conc"] ? 0 += 1;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
28
Task/Metaprogramming/Rascal/metaprogramming-3.rascal
Normal file
28
Task/Metaprogramming/Rascal/metaprogramming-3.rascal
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
public data TYPE =
|
||||
natural() | string();
|
||||
|
||||
public alias PicoId = str;
|
||||
|
||||
public data PROGRAM =
|
||||
program(list[DECL] decls, list[STATEMENT] stats);
|
||||
|
||||
public data DECL =
|
||||
decl(PicoId name, TYPE tp);
|
||||
|
||||
public data EXP =
|
||||
id(PicoId name)
|
||||
| natCon(int iVal)
|
||||
| strCon(str sVal)
|
||||
| add(EXP left, EXP right)
|
||||
| sub(EXP left, EXP right)
|
||||
| conc(EXP left, EXP right)
|
||||
;
|
||||
|
||||
public data STATEMENT =
|
||||
asgStat(PicoId name, EXP exp)
|
||||
| ifElseStat(EXP exp, list[STATEMENT] thenpart, list[STATEMENT] elsepart)
|
||||
| ifThenStat(EXP exp, list[STATEMENT] thenpart)
|
||||
| whileStat(EXP exp, list[STATEMENT] body)
|
||||
| doUntilStat(EXP exp, list[STATEMENT] body)
|
||||
| unlessStat(EXP exp, list[STATEMENT] body)
|
||||
;
|
||||
56
Task/Metaprogramming/Rascal/metaprogramming-4.rascal
Normal file
56
Task/Metaprogramming/Rascal/metaprogramming-4.rascal
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
module lang::pico::Syntax
|
||||
|
||||
import Prelude;
|
||||
|
||||
lexical Id = [a-z][a-z0-9]* !>> [a-z0-9];
|
||||
lexical Natural = [0-9]+ ;
|
||||
lexical String = "\"" ![\"]* "\"";
|
||||
|
||||
layout Layout = WhitespaceAndComment* !>> [\ \t\n\r%];
|
||||
|
||||
lexical WhitespaceAndComment
|
||||
= [\ \t\n\r]
|
||||
| @category="Comment" "%" ![%]+ "%"
|
||||
| @category="Comment" "%%" ![\n]* $
|
||||
;
|
||||
|
||||
start syntax Program
|
||||
= program: "begin" Declarations decls {Statement ";"}* body "end" ;
|
||||
|
||||
syntax Declarations
|
||||
= "declare" {Declaration ","}* decls ";" ;
|
||||
|
||||
syntax Declaration = decl: Id id ":" Type tp;
|
||||
|
||||
syntax Type
|
||||
= natural:"natural"
|
||||
| string :"string"
|
||||
;
|
||||
|
||||
syntax Statement
|
||||
= asgStat: Id var ":=" Expression val
|
||||
| ifElseStat: "if" Expression cond "then" {Statement ";"}* thenPart "else" {Statement ";"}* elsePart "fi"
|
||||
| ifThenStat: "if" Expression cond "then" {Statement ";"}* thenPart "fi"
|
||||
| whileStat: "while" Expression cond "do" {Statement ";"}* body "od"
|
||||
| doUntilStat: "do" {Statement ";"}* body "until" Expression cond "od"
|
||||
| unlessStat: Statement "unless" Expression cond
|
||||
;
|
||||
|
||||
syntax Expression
|
||||
= id: Id name
|
||||
| strCon: String string
|
||||
| natCon: Natural natcon
|
||||
| bracket "(" Expression e ")"
|
||||
> left conc: Expression lhs "||" Expression rhs
|
||||
> left ( add: Expression lhs "+" Expression rhs
|
||||
| sub: Expression lhs "-" Expression rhs
|
||||
)
|
||||
;
|
||||
|
||||
public start[Program] program(str s) {
|
||||
return parse(#start[Program], s);
|
||||
}
|
||||
|
||||
public start[Program] program(str s, loc l) {
|
||||
return parse(#start[Program], s, l);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue