From cbe0bd3df1f1ddf458de751d28eb1df73708113c Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Fri, 24 Feb 2006 08:02:00 +0000 Subject: [PATCH] more or less done with the syntx --- documentation | 14 ++++++++------ syntax.cf | 10 +++++----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/documentation b/documentation index 2d3fcac..c77568b 100644 --- a/documentation +++ b/documentation @@ -1,7 +1,7 @@ ####### DOCUMENTATIATOIAITAT ION ######## -a simple c-like language with support for if/else-statements, while-loops and the standard arithmetic (+, -, /, *) and comparison expressions (<, >, <=, >=, ==, !=). also, increase/decrease expressions (++, --) are supported. +a simple c-like language with support for if/else-statements, while-loops and the standard arithmetic (+, -, /, *) and comparison expressions (<, >, <=, >=, ==, !=). also, post increase/decrease expressions (++, --) are supported. data types: integers and booleans. @@ -9,20 +9,22 @@ integers and booleans. comments: // and /* */ comments are allowed. +(For compilation to work the Bool type in Abssyntax has to be removed so the internal haskell type is used) + shift/reduce conflicts: -30 conflicts in total. +18 conflicts in total. 1) Exp1 followed by (<,<=,>,>=,==,!=,+,-) 8 conflicts: In these cases the Exp1 could've been reduced to Exp, but happy does the correct thing and shifts the operator token onto the stack, since Exp followed by these operators doesn't match any rules. -2) Exp2 followed by (*,/) 6 conflicts: +2) Exp2 followed by (*,/) 4 conflicts: In two cases the Exp2 expression could be reduced to Exp1, but this wouldn't match the rules for these operators, so shifting is the correct action. -In four other cases the Exp2 in front of these operators can be reduced to addition and subtraction expressions, which would destroy operator priority, so shifting is correct here. +In two other cases the Exp2 in front of these operators can be reduced to addition and subtraction expressions, which would destroy operator priority, so shifting is correct here. -3) Exp1 followed by (+,-) 12 conflicts: -In all these cases Exp1 could be reduced together with another Exp1 and a comparative operator to an Exp, but just as in the above case this would be very bad for operator priority, so shifting is right here. +3) Exp1 followed by (+,-) 2 conflicts: +In both these cases Exp1 could be reduced together with another Exp1 and a comparative operator to an Exp, but just as in the above case this would be very bad for operator priority, so shifting is right here. 4) if with else: 1 conflict An if statement before the else could be reduced to an if statement lacking the else, but the correct thing is to shift it onto the stack. diff --git a/syntax.cf b/syntax.cf index 28e93f9..fae1234 100644 --- a/syntax.cf +++ b/syntax.cf @@ -16,16 +16,15 @@ SWhile. Stm ::= "while" "(" Exp ")" Stm ; -- SFor. Stm ::= "for" "(" Stm Exp ";" Exp ")" Stm ; SPrint. Stm ::= "print" Exp ";" ; --- VVar. Var ::= Ident ; --- VAss. Var ::= Ident "=" Exp; - BExp. Exp ::= Exp1 BOp Exp1 ; op1. Exp1 ::= Exp1 Op1 Exp2 ; define op1 e1 o e2 = OpExp e1 o e2 ; op2. Exp2 ::= Exp2 Op2 Exp3 ; define op2 e1 o e2 = OpExp e1 o e2 ; -EIncr. Exp3 ::= Ident "++" ; -EDecr. Exp3 ::= Ident "--" ; +postIncr. Exp3 ::= Ident "++" ; +define postIncr i = EPost i Plus ; +postDecr. Exp3 ::= Ident "--" ; +define postDecr i = EPost i Minus ; EVar. Exp3 ::= Ident ; EAss. Exp3 ::= Ident "=" Exp; EInt. Exp3 ::= Integer ; @@ -71,6 +70,7 @@ internal SNoop. Stm ::= ; internal EDefault. Exp ::= ; internal OpExp. Exp ::= Exp Op Exp ; internal NoType. Type ::= ; +internal EPost. Exp ::= Ident Op1 ; comment "/*" "*/" ; comment "//" ; -- 2.39.2