Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
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