]> ruin.nu Git - proglang.git/commitdiff
added not
authorMichael Andreen <harv@ruin.nu>
Tue, 28 Feb 2006 08:03:56 +0000 (08:03 +0000)
committerMichael Andreen <harv@ruin.nu>
Tue, 28 Feb 2006 08:03:56 +0000 (08:03 +0000)
Abssyntax.hs
Docsyntax.tex
Lexsyntax.x
Parsyntax.y
Printsyntax.hs
Skelsyntax.hs
Typecheck.hs
examples/if
syntax.cf

index 4cc8d19eb8e0dea898b8239177d6c32e73e7fee9..d8ef904d06766fd3ccab71ee41d1ed9e9ceb319b 100644 (file)
@@ -19,6 +19,7 @@ data Exp =
  | EVar Ident
  | EInt Integer
  | ENeg Exp
  | EVar Ident
  | EInt Integer
  | ENeg Exp
+ | ENot Exp
  | EBool Bool
  | EReadI
  | EReadB
  | EBool Bool
  | EReadI
  | EReadB
index 89c1a0f72a0fd971c506d65c77b011cc581914a4..09e48987172d66864ffffae73e3e784dc9506f2b 100644 (file)
@@ -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{!}} &{\symb{{$<$}}} &{\symb{{$<$}{$=$}}} \\
+{\symb{{$>$}}} &{\symb{{$>$}{$=$}}} &{\symb{{$=$}{$=$}}} \\
+{\symb{!{$=$}}} &{\symb{{$+$}}} &{\symb{*}} \\
+{\symb{/}} & & \\
 \end{tabular}\\
 
 \subsection*{Comments}
 \end{tabular}\\
 
 \subsection*{Comments}
@@ -104,6 +105,7 @@ All other symbols are terminals.\\
  & {\delimit}  &{\nonterminal{Ident}}  \\
  & {\delimit}  &{\nonterminal{Integer}}  \\
  & {\delimit}  &{\terminal{{$-$}}} {\nonterminal{Exp3}}  \\
  & {\delimit}  &{\nonterminal{Ident}}  \\
  & {\delimit}  &{\nonterminal{Integer}}  \\
  & {\delimit}  &{\terminal{{$-$}}} {\nonterminal{Exp3}}  \\
+ & {\delimit}  &{\terminal{!}} {\nonterminal{Exp3}}  \\
  & {\delimit}  &{\nonterminal{Bool}}  \\
  & {\delimit}  &{\terminal{readInt}}  \\
  & {\delimit}  &{\terminal{readBool}}  \\
  & {\delimit}  &{\nonterminal{Bool}}  \\
  & {\delimit}  &{\terminal{readInt}}  \\
  & {\delimit}  &{\terminal{readBool}}  \\
index 00277a9c306432c3c5bf8baf9347c119a74b196a..2d4ef67758974929d70389241cb78382e0e1a8cf 100644 (file)
@@ -16,7 +16,7 @@ $i = [$l $d _ ']          -- identifier character
 $u = [\0-\255]          -- universal: any character
 
 @rsyms =    -- symbols and non-identifier-like reserved words
 $u = [\0-\255]          -- universal: any character
 
 @rsyms =    -- symbols and non-identifier-like reserved words
-   \= | \; | \{ | \} | \( | \) | \+ \+ | \- \- | \- | \< | \< \= | \> | \> \= | \= \= | \! \= | \+ | \* | \/
+   \= | \; | \{ | \} | \( | \) | \+ \+ | \- \- | \- | \! | \< | \< \= | \> | \> \= | \= \= | \! \= | \+ | \* | \/
 
 :-
 "//" [.]* ; -- Toss single line comments
 
 :-
 "//" [.]* ; -- Toss single line comments
index dbd776705fe7fbb566e77bf45bda1e20787638ef..461c967b366f8bf473c2b90877643b884aac1490 100644 (file)
@@ -23,6 +23,7 @@ import ErrM
  '++' { PT _ (TS "++") }
  '--' { PT _ (TS "--") }
  '-' { PT _ (TS "-") }
  '++' { PT _ (TS "++") }
  '--' { PT _ (TS "--") }
  '-' { PT _ (TS "-") }
+ '!' { 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 }
   | Ident { EVar $1 }
   | Integer { EInt $1 }
   | '-' Exp3 { ENeg $2 }
+  | '!' Exp3 { ENot $2 }
   | Bool { EBool $1 }
   | 'readInt' { EReadI }
   | 'readBool' { EReadB }
   | Bool { EBool $1 }
   | 'readInt' { EReadI }
   | 'readBool' { EReadB }
index feb0b2332dce7a464f6db733404e1df969d77f70..e84a1d333e8c46d73773924fa4869e035a7d191e 100644 (file)
@@ -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])
    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")])
    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")])
index 5f49a5b5a4d392571d9009e04c94d63961e34ff8..07898ef6d2aa24e4e2ff417f75af2b21268368cb 100644 (file)
@@ -37,6 +37,7 @@ transExp x = case x of
   EVar id  -> failure x
   EInt n  -> failure x
   ENeg exp  -> failure x
   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
   EBool bool  -> failure x
   EReadI  -> failure x
   EReadB  -> failure x
index 38ee8fe070973d51b4602dc6a39e90c928c9fcce..52f9816b07fdc277cdb385a70ed5c3b3588b849b 100644 (file)
@@ -40,6 +40,9 @@ typeCheckExp (EPost i op) = do
 typeCheckExp (ENeg e) = do
        TInt <- typeCheckExp e
        return TInt
 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
 
 typeCheckVar :: (MonadState Types m) => Ident -> m Type 
 typeCheckVar i = do
index 4f6040efd83e9541de7e29baf496194caf9e66de..5559a925822952633747faf9415ce6524c7c5a5b 100644 (file)
@@ -1,7 +1,7 @@
 /*
 tests if and if/else
 */
 /*
 tests if and if/else
 */
-if (readBool) {
+if (!readBool) {
   if (readInt < 0)
     print true;
   else
   if (readInt < 0)
     print true;
   else
index 313fa556810e0dff5de9602959cdb74cd81073b5..de173e86a1fc5cd4f98b837cdd8b3622478bf0b2 100644 (file)
--- 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 ;
 EVar.     Exp3    ::= Ident ;
 EInt.     Exp3    ::= Integer ;
 ENeg.     Exp3    ::= "-" Exp3 ;
--- ENot.     Exp3    ::= "!" Exp3 ;
+ENot.     Exp3    ::= "!" Exp3 ;
 EBool.    Exp3    ::= Bool ;
 EReadI.   Exp3    ::= "readInt" ;
 EReadB.   Exp3    ::= "readBool" ;
 EBool.    Exp3    ::= Bool ;
 EReadI.   Exp3    ::= "readInt" ;
 EReadB.   Exp3    ::= "readBool" ;