From: Michael Andreen Date: Tue, 28 Feb 2006 08:03:56 +0000 (+0000) Subject: added not X-Git-Url: https://ruin.nu/git/?p=proglang.git;a=commitdiff_plain;h=9d0e3c89b286456549c68a816d0729f193498f6a added not --- diff --git a/Abssyntax.hs b/Abssyntax.hs index 4cc8d19..d8ef904 100644 --- a/Abssyntax.hs +++ b/Abssyntax.hs @@ -19,6 +19,7 @@ data Exp = | EVar Ident | EInt Integer | ENeg Exp + | ENot Exp | EBool Bool | EReadI | EReadB diff --git a/Docsyntax.tex b/Docsyntax.tex index 89c1a0f..09e4898 100644 --- a/Docsyntax.tex +++ b/Docsyntax.tex @@ -52,9 +52,10 @@ The symbols used in syntax are the following: \\ {\symb{{$=$}}} &{\symb{;}} &{\symb{\{}} \\ {\symb{\}}} &{\symb{(}} &{\symb{)}} \\ {\symb{{$+$}{$+$}}} &{\symb{{$-$}{$-$}}} &{\symb{{$-$}}} \\ -{\symb{{$<$}}} &{\symb{{$<$}{$=$}}} &{\symb{{$>$}}} \\ -{\symb{{$>$}{$=$}}} &{\symb{{$=$}{$=$}}} &{\symb{!{$=$}}} \\ -{\symb{{$+$}}} &{\symb{*}} &{\symb{/}} \\ +{\symb{!}} &{\symb{{$<$}}} &{\symb{{$<$}{$=$}}} \\ +{\symb{{$>$}}} &{\symb{{$>$}{$=$}}} &{\symb{{$=$}{$=$}}} \\ +{\symb{!{$=$}}} &{\symb{{$+$}}} &{\symb{*}} \\ +{\symb{/}} & & \\ \end{tabular}\\ \subsection*{Comments} @@ -104,6 +105,7 @@ All other symbols are terminals.\\ & {\delimit} &{\nonterminal{Ident}} \\ & {\delimit} &{\nonterminal{Integer}} \\ & {\delimit} &{\terminal{{$-$}}} {\nonterminal{Exp3}} \\ + & {\delimit} &{\terminal{!}} {\nonterminal{Exp3}} \\ & {\delimit} &{\nonterminal{Bool}} \\ & {\delimit} &{\terminal{readInt}} \\ & {\delimit} &{\terminal{readBool}} \\ diff --git a/Lexsyntax.x b/Lexsyntax.x index 00277a9..2d4ef67 100644 --- a/Lexsyntax.x +++ b/Lexsyntax.x @@ -16,7 +16,7 @@ $i = [$l $d _ '] -- identifier character $u = [\0-\255] -- universal: any character @rsyms = -- symbols and non-identifier-like reserved words - \= | \; | \{ | \} | \( | \) | \+ \+ | \- \- | \- | \< | \< \= | \> | \> \= | \= \= | \! \= | \+ | \* | \/ + \= | \; | \{ | \} | \( | \) | \+ \+ | \- \- | \- | \! | \< | \< \= | \> | \> \= | \= \= | \! \= | \+ | \* | \/ :- "//" [.]* ; -- Toss single line comments diff --git a/Parsyntax.y b/Parsyntax.y index dbd7767..461c967 100644 --- a/Parsyntax.y +++ b/Parsyntax.y @@ -23,6 +23,7 @@ import ErrM '++' { PT _ (TS "++") } '--' { PT _ (TS "--") } '-' { PT _ (TS "-") } + '!' { PT _ (TS "!") } '<' { PT _ (TS "<") } '<=' { PT _ (TS "<=") } '>' { PT _ (TS ">") } @@ -91,6 +92,7 @@ Exp3 : Ident '++' { postIncr_ $1 } | Ident { EVar $1 } | Integer { EInt $1 } | '-' Exp3 { ENeg $2 } + | '!' Exp3 { ENot $2 } | Bool { EBool $1 } | 'readInt' { EReadI } | 'readBool' { EReadB } diff --git a/Printsyntax.hs b/Printsyntax.hs index feb0b23..e84a1d3 100644 --- a/Printsyntax.hs +++ b/Printsyntax.hs @@ -107,6 +107,7 @@ instance Print Exp where EVar id -> prPrec i 3 (concatD [prt 0 id]) EInt n -> prPrec i 3 (concatD [prt 0 n]) ENeg exp -> prPrec i 3 (concatD [doc (showString "-") , prt 3 exp]) + ENot exp -> prPrec i 3 (concatD [doc (showString "!") , prt 3 exp]) EBool bool -> prPrec i 3 (concatD [prt 0 bool]) EReadI -> prPrec i 3 (concatD [doc (showString "readInt")]) EReadB -> prPrec i 3 (concatD [doc (showString "readBool")]) diff --git a/Skelsyntax.hs b/Skelsyntax.hs index 5f49a5b..07898ef 100644 --- a/Skelsyntax.hs +++ b/Skelsyntax.hs @@ -37,6 +37,7 @@ transExp x = case x of EVar id -> failure x EInt n -> failure x ENeg exp -> failure x + ENot exp -> failure x EBool bool -> failure x EReadI -> failure x EReadB -> failure x diff --git a/Typecheck.hs b/Typecheck.hs index 38ee8fe..52f9816 100644 --- a/Typecheck.hs +++ b/Typecheck.hs @@ -40,6 +40,9 @@ typeCheckExp (EPost i op) = do typeCheckExp (ENeg e) = do TInt <- typeCheckExp e return TInt +typeCheckExp (ENot e) = do + TBool <- typeCheckExp e + return TBool typeCheckVar :: (MonadState Types m) => Ident -> m Type typeCheckVar i = do diff --git a/examples/if b/examples/if index 4f6040e..5559a92 100644 --- a/examples/if +++ b/examples/if @@ -1,7 +1,7 @@ /* tests if and if/else */ -if (readBool) { +if (!readBool) { if (readInt < 0) print true; else diff --git a/syntax.cf b/syntax.cf index 313fa55..de173e8 100644 --- a/syntax.cf +++ b/syntax.cf @@ -30,7 +30,7 @@ define postDecr i = EPost i Minus ; EVar. Exp3 ::= Ident ; EInt. Exp3 ::= Integer ; ENeg. Exp3 ::= "-" Exp3 ; --- ENot. Exp3 ::= "!" Exp3 ; +ENot. Exp3 ::= "!" Exp3 ; EBool. Exp3 ::= Bool ; EReadI. Exp3 ::= "readInt" ; EReadB. Exp3 ::= "readBool" ;