Skip to content

Commit

Permalink
+ifthenelse, +booleans
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@692 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Nov 1, 2009
1 parent e197e6d commit e48ec5e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
31 changes: 30 additions & 1 deletion topics/exercises/while1/Parser.pro
Expand Up @@ -22,11 +22,40 @@ statement(assign(identifier(V),E)) -->
expression(E).

% Conditional statement
% (homework)
statement(ifthenelse(E,S1,S2)) -->
keyword("if"),
expression(E),
keyword("then"),
statement(S1),
keyword("else"),
statement(S2).

% Expressions
% Number is a an expression
expression(number(N)) --> number(N).

% Boolean primitives are expressions
expression(true) --> keyword("true").
expression(false) --> keyword("false").

% Comparison is a boolean expression: greater than
expression(isgreaterthan(V,E)) -->
identifier(V),
keyword(">"),
expression(E).

% Less than
expression(islessthan(V,E)) -->
identifier(V),
keyword("<"),
expression(E).

% Equals
expression(equals(V,E)) -->
identifier(V),
keyword("=="),
expression(E).

% Dealing with spaces
spaces --> [0' ], spaces. %'
spaces --> [].
Expand Down
2 changes: 1 addition & 1 deletion topics/exercises/while1/input.txt
@@ -1 +1 @@
x:=2;y:=2
if x == 0 then y:=2 else z:=2; skip

0 comments on commit e48ec5e

Please sign in to comment.