module lang::pico::\syntax::Main
rascal-0.34.0
Usage
import lang::pico::\syntax::Main;
Dependencies
import ParseTree;
syntax Program
start syntax Program
= program: "begin" Declarations decls {Statement ";"}* body "end" ;
syntax Declarations
syntax Declarations
= "declare" {IdType ","}* decls ";" ;
syntax IdType
syntax IdType = idtype: Id id ":" Type t;
syntax Statement
syntax Statement
= assign: Id var ":=" Expression val
| cond: "if" Expression cond "then" {Statement ";"}* thenPart "else" {Statement ";"}* elsePart "fi"
| cond: "if" Expression cond "then" {Statement ";"}* thenPart "fi"
| loop: "while" Expression cond "do" {Statement ";"}* body "od"
;
syntax Type
syntax Type
= natural:"natural"
| string :"string"
| nil :"nil-type"
;
syntax Expression
syntax Expression
= id: Id name
| strcon: String string
| natcon: Natural natcon
| bracket "(" Expression e ")"
> left concat: Expression lhs "||" Expression rhs
> left ( add: Expression lhs "+" Expression rhs
| min: Expression lhs "-" Expression rhs
)
;
syntax Id
lexical Id = [a-z][a-z0-9]* !>> [a-z0-9];
syntax Natural
lexical Natural = [0-9]+ ;
syntax String
lexical String = "\"" ![\"]* "\"";
syntax Layout
layout Layout = WhitespaceAndComment* !>> [\ \t\n\r%];
syntax WhitespaceAndComment
lexical WhitespaceAndComment
= [\ \t\n\r]
| @category="Comment" "%" ![%]+ "%"
| @category="Comment" "%%" ![\n]* $
;
function program
start[Program] program(str s)
start[Program] program(str s, loc l)