Module rurtle::parse
[−]
[src]
Parsing module for Rurtle programs.
Note that parsing requires some additional information, i.e. the number of arguments for a function. Function calls in Rurtle need neither parenthesis nor something else, so this is legal:
FUNCA FUNCB 10
Depending on how many arguments each function takes, this may be parsed as
either funca(funcb(10))
or funca(funcb(), 10)
.
Grammar
A EBNF-like (incomplete) grammar may look like
root := {statement} ;
statement := learn-def | if-stmt | repeat-stmt | while-stmt | return-stmt |
try-stmt | expression ;
learn-def := 'LEARN' identifier {variable} 'DO' {statement} 'END' ;
if-stmt := 'IF' expression 'DO' {statement} ['ELSE' {statement}]'END' ;
repeat-stmt := 'REPEAT' expression 'DO' {statement} 'END' ;
while-stmt := 'WHILE' expression 'DO' {statement} 'END' ;
return-stmt := 'RETURN' expression ;
try-stmt := 'TRY' {statement} 'ELSE' {statement} 'END' ;
variable := ':' identifier ;
identifier := idenfitier-start {identifier-cont} ;
idenfitier-start := <any alphabetic character> ;
idenfitier-cont := <any alpabetic or numeric character> ;
expression := comparison ;
comparison := expr [comp_op expr] ;
comp_op := '=' | '<' | '>' | ''<=' | '>=' | '<>' ;
expr := product {('+' | '-') product} ;
product := factor {('*' | '/') factor} ;
factor := '(' expression ')' | list | variable | string | number | (identifier {expression}) ;
list := '[' {expression} ']' ;
string := '"' {<any character>} '"' ;
number := ['+' | '-'] <any valid floating point number literal> ;
Modules
ast |
Abstract Syntax Tree |
Structs
ParseError | |
Parser |
A |
Enums
ParseErrorKind |
Type Definitions
FuncMap |
A |
ParseResult |