Compare commits

...

15 Commits

2 changed files with 210 additions and 130 deletions

View File

@ -18,11 +18,91 @@ testBooleanField = TestCase $
testIntField = TestCase $ testIntField = TestCase $
assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $ assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $
parse [CLASS,IDENTIFIER "WithInt",LBRACKET,INT,IDENTIFIER "value",SEMICOLON,RBRACKET] parse [CLASS,IDENTIFIER "WithInt",LBRACKET,INT,IDENTIFIER "value",SEMICOLON,RBRACKET]
testCustomTypeField = TestCase $
assertEqual "expect class with foo field" [Class "WithFoo" [] [VariableDeclaration "Foo" "value" Nothing]] $
parse [CLASS,IDENTIFIER "WithFoo",LBRACKET,IDENTIFIER "Foo",IDENTIFIER "value",SEMICOLON,RBRACKET]
testMultipleDeclarationSameLine = TestCase $
assertEqual "expect class with two int fields" [Class "TwoInts" [] [VariableDeclaration "int" "num1" Nothing, VariableDeclaration "int" "num2" Nothing]] $
parse [CLASS,IDENTIFIER "TwoInts",LBRACKET,INT,IDENTIFIER "num1",COMMA,IDENTIFIER "num2",SEMICOLON,RBRACKET]
testMultipleDeclarations = TestCase $
assertEqual "expect class with int and char field" [Class "Multiple" [] [VariableDeclaration "int" "value" Nothing, VariableDeclaration "char" "letter" Nothing]] $
parse [CLASS,IDENTIFIER "Multiple",LBRACKET,INT,IDENTIFIER "value",SEMICOLON,CHAR,IDENTIFIER "letter",SEMICOLON,RBRACKET]
testWithModifier = TestCase $
assertEqual "expect class with int field" [Class "WithInt" [] [VariableDeclaration "int" "value" Nothing]] $
parse [ABSTRACT,CLASS,IDENTIFIER "WithInt",LBRACKET,PUBLIC,INT,IDENTIFIER "value",SEMICOLON,RBRACKET]
testEmptyMethod = TestCase $
assertEqual "expect class with method" [Class "WithMethod" [MethodDeclaration "int" "foo" [] (Block [])] []] $
parse [CLASS,IDENTIFIER "WithMethod",LBRACKET,INT,IDENTIFIER "foo",LBRACE,RBRACE,SEMICOLON,RBRACKET]
testEmptyPrivateMethod = TestCase $
assertEqual "expect class with method" [Class "WithMethod" [MethodDeclaration "int" "foo" [] (Block [])] []] $
parse [CLASS,IDENTIFIER "WithMethod",LBRACKET,PRIVATE,INT,IDENTIFIER "foo",LBRACE,RBRACE,LBRACKET,RBRACKET,RBRACKET]
testEmptyVoidMethod = TestCase $
assertEqual "expect class with method" [Class "WithMethod" [MethodDeclaration "void" "foo" [] (Block [])] []] $
parse [CLASS,IDENTIFIER "WithMethod",LBRACKET,VOID,IDENTIFIER "foo",LBRACE,RBRACE,LBRACKET,RBRACKET,RBRACKET]
testEmptyMethodWithParam = TestCase $
assertEqual "expect class with method with param" [Class "WithParam" [MethodDeclaration "void" "foo" [ParameterDeclaration "int" "param"] (Block [])] []] $
parse [CLASS,IDENTIFIER "WithParam",LBRACKET,VOID,IDENTIFIER "foo",LBRACE,INT,IDENTIFIER "param",RBRACE,SEMICOLON,RBRACKET]
testEmptyMethodWithParams = TestCase $
assertEqual "expect class with multiple params" [Class "WithParams" [MethodDeclaration "void" "foo" [ParameterDeclaration "int" "p1",ParameterDeclaration "Custom" "p2"] (Block [])] []] $
parse [CLASS,IDENTIFIER "WithParams",LBRACKET,VOID,IDENTIFIER "foo",LBRACE,INT,IDENTIFIER "p1",COMMA,IDENTIFIER "Custom",IDENTIFIER "p2",RBRACE,SEMICOLON,RBRACKET]
testClassWithMethodAndField = TestCase $
assertEqual "expect class with method and field" [Class "WithMethodAndField" [MethodDeclaration "void" "foo" [] (Block []), MethodDeclaration "int" "bar" [] (Block [])] [VariableDeclaration "int" "value" Nothing]] $
parse [CLASS,IDENTIFIER "WithMethodAndField",LBRACKET,VOID,IDENTIFIER "foo",LBRACE,RBRACE,LBRACKET,RBRACKET,INT,IDENTIFIER "value",SEMICOLON,INT,IDENTIFIER "bar",LBRACE,RBRACE,SEMICOLON,RBRACKET]
testClassWithConstructor = TestCase $
assertEqual "expect class with constructor" [Class "WithConstructor" [MethodDeclaration "WithConstructor" "<init>" [] (Block [])] []] $
parse [CLASS,IDENTIFIER "WithConstructor",LBRACKET,IDENTIFIER "WithConstructor",LBRACE,RBRACE,LBRACKET,RBRACKET,RBRACKET]
testEmptyBlock = TestCase $ assertEqual "expect empty block" (Block []) $ parseBlock [LBRACKET,RBRACKET]
testBlockWithLocalVarDecl = TestCase $
assertEqual "expect block with local var delcaration" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "localvar" Nothing]) $
parseBlock [LBRACKET,INT,IDENTIFIER "localvar",SEMICOLON,RBRACKET]
testBlockWithMultipleLocalVarDecls = TestCase $
assertEqual "expect block with multiple local var declarations" (Block [LocalVariableDeclaration $ VariableDeclaration "int" "var1" Nothing, LocalVariableDeclaration $ VariableDeclaration "boolean" "var2" Nothing]) $
parseBlock [LBRACKET,INT,IDENTIFIER "var1",SEMICOLON,BOOLEAN,IDENTIFIER "var2",SEMICOLON,RBRACKET]
testNestedBlocks = TestCase $
assertEqual "expect block with block inside" (Block [Block []]) $
parseBlock [LBRACKET,LBRACKET,RBRACKET,RBRACKET]
testBlockWithEmptyStatement = TestCase $
assertEqual "expect empty block" (Block []) $
parseBlock [LBRACKET,SEMICOLON,SEMICOLON,RBRACKET]
testExpressionIntLiteral = TestCase $
assertEqual "expect IntLiteral" (IntegerLiteral 3) $
parseExpression [INTEGERLITERAL 3]
testFieldWithInitialization = TestCase $
assertEqual "expect Class with initialized field" [Class "WithInitField" [] [VariableDeclaration "int" "number" $ Just $ IntegerLiteral 3]] $
parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,INT,IDENTIFIER "number",ASSIGN,INTEGERLITERAL 3,SEMICOLON,RBRACKET]
testLocalBoolWithInitialization = TestCase $
assertEqual "expect block with with initialized local var" (Block [LocalVariableDeclaration $ VariableDeclaration "boolean" "b" $ Just $ BooleanLiteral False]) $
parseBlock [LBRACKET,BOOLEAN,IDENTIFIER "b",ASSIGN,BOOLLITERAL False,SEMICOLON,RBRACKET]
testFieldNullWithInitialization = TestCase $
assertEqual "expect Class with initialized field" [Class "WithInitField" [] [VariableDeclaration "Object" "bar" $ Just NullLiteral]] $
parse [CLASS,IDENTIFIER "WithInitField",LBRACKET,IDENTIFIER "Object",IDENTIFIER "bar",ASSIGN,NULLLITERAL,SEMICOLON,RBRACKET]
tests = TestList [ tests = TestList [
testSingleEmptyClass, testSingleEmptyClass,
testTwoEmptyClasses, testTwoEmptyClasses,
testBooleanField, testBooleanField,
testIntField testIntField,
testCustomTypeField,
testMultipleDeclarations,
testWithModifier,
testEmptyMethod,
testEmptyPrivateMethod,
testEmptyVoidMethod,
testEmptyMethodWithParam,
testEmptyMethodWithParams,
testClassWithMethodAndField,
testClassWithConstructor,
testEmptyBlock,
testBlockWithLocalVarDecl,
testBlockWithMultipleLocalVarDecls,
testNestedBlocks,
testBlockWithEmptyStatement,
testExpressionIntLiteral,
testFieldWithInitialization,
testLocalBoolWithInitialization,
testFieldNullWithInitialization
] ]

View File

@ -1,12 +1,15 @@
{ {
module Parser.JavaParser (parse) where module Parser.JavaParser (parse, parseBlock, parseExpression) where
import Ast import Ast
import Parser.Lexer import Parser.Lexer
} }
%name parse %name parse
%name parseBlock block
%name parseExpression expression
%tokentype { Token } %tokentype { Token }
%error { parseError } %error { parseError }
%errorhandlertype explist
%token %token
BOOLEAN { BOOLEAN } BOOLEAN { BOOLEAN }
@ -80,17 +83,17 @@ compilationunit : typedeclarations { $1 }
typedeclarations : typedeclaration { [$1] } typedeclarations : typedeclaration { [$1] }
| typedeclarations typedeclaration { $1 ++ [$2] } | typedeclarations typedeclaration { $1 ++ [$2] }
name : qualifiedname { } name : simplename { $1 }
| simplename { } -- | qualifiedname { }
typedeclaration : classdeclaration { $1 } typedeclaration : classdeclaration { $1 }
qualifiedname : name DOT IDENTIFIER { } qualifiedname : name DOT IDENTIFIER { }
simplename : IDENTIFIER { } simplename : IDENTIFIER { $1 }
classdeclaration : CLASS IDENTIFIER classbody { case $3 of (methods, fields) -> Class $2 methods fields } classdeclaration : CLASS IDENTIFIER classbody { case $3 of (methods, fields) -> Class $2 methods fields }
-- | modifiers CLASS IDENTIFIER classbody { case $4 of (methods, fields) -> Class $3 methods fields } | modifiers CLASS IDENTIFIER classbody { case $4 of (methods, fields) -> Class $3 methods fields }
classbody : LBRACKET RBRACKET { ([], []) } classbody : LBRACKET RBRACKET { ([], []) }
| LBRACKET classbodydeclarations RBRACKET { $2 } | LBRACKET classbodydeclarations RBRACKET { $2 }
@ -103,11 +106,11 @@ classbodydeclarations : classbodydeclaration {
MethodDecl method -> ([method], []) MethodDecl method -> ([method], [])
FieldDecls fields -> ([], fields) FieldDecls fields -> ([], fields)
} }
-- | classbodydeclarations classbodydeclaration { | classbodydeclarations classbodydeclaration {
-- case ($1, $2) of case ($1, $2) of
-- ((methods, fields), MethodDecl method) -> ((methods ++ [method]), fields) ((methods, fields), MethodDecl method) -> ((methods ++ [method]), fields)
-- ((methods, fields), FieldDecl field) -> (methods, (fields ++ [field])) ((methods, fields), FieldDecls newFields) -> (methods, (fields ++ newFields))
-- } }
modifier : PUBLIC { } modifier : PUBLIC { }
| PROTECTED { } | PROTECTED { }
@ -118,51 +121,51 @@ modifier : PUBLIC { }
classtype : classorinterfacetype{ } classtype : classorinterfacetype{ }
classbodydeclaration : classmemberdeclaration { $1 } classbodydeclaration : classmemberdeclaration { $1 }
-- | constructordeclaration { FieldDecl $ VariableDeclaration "int" "a" Nothing } -- TODO | constructordeclaration { $1 }
classorinterfacetype : name{ } classorinterfacetype : name { $1 }
classmemberdeclaration : fielddeclaration { $1 } classmemberdeclaration : fielddeclaration { $1 }
-- | methoddeclaration { } | methoddeclaration { $1 }
constructordeclaration : constructordeclarator constructorbody { } constructordeclaration : constructordeclarator constructorbody { case $1 of (classname, parameters) -> MethodDecl $ MethodDeclaration classname "<init>" parameters $2 }
| modifiers constructordeclarator constructorbody { } | modifiers constructordeclarator constructorbody { case $2 of (classname, parameters) -> MethodDecl $ MethodDeclaration classname "<init>" parameters $3 }
fielddeclaration : type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $1) $2 } fielddeclaration : type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $1) $2 }
-- | modifiers type variabledeclarators SEMICOLON {} | modifiers type variabledeclarators SEMICOLON { FieldDecls $ map (convertDeclarator $2) $3 }
methoddeclaration : methodheader methodbody { } methoddeclaration : methodheader methodbody { case $1 of (returnType, (name, parameters)) -> MethodDecl (MethodDeclaration returnType name parameters $2) }
block : LBRACKET RBRACKET { } block : LBRACKET RBRACKET { Block [] }
| LBRACKET blockstatements RBRACKET { } | LBRACKET blockstatements RBRACKET { Block $2 }
constructordeclarator : simplename LBRACE RBRACE { } constructordeclarator : simplename LBRACE RBRACE { ($1, []) }
| simplename LBRACE formalparameterlist RBRACE { } | simplename LBRACE formalparameterlist RBRACE { ($1, $3) }
constructorbody : LBRACKET RBRACKET { } constructorbody : LBRACKET RBRACKET { Block [] }
| LBRACKET explicitconstructorinvocation RBRACKET { } -- | LBRACKET explicitconstructorinvocation RBRACKET { }
| LBRACKET blockstatements RBRACKET { } -- | LBRACKET blockstatements RBRACKET { }
| LBRACKET explicitconstructorinvocation blockstatements RBRACKET { } -- | LBRACKET explicitconstructorinvocation blockstatements RBRACKET { }
methodheader : type methoddeclarator { } methodheader : type methoddeclarator { ($1, $2) }
| modifiers type methoddeclarator { } | modifiers type methoddeclarator { ($2, $3) }
| VOID methoddeclarator { } | VOID methoddeclarator { ("void", $2) }
| modifiers VOID methoddeclarator { } | modifiers VOID methoddeclarator { ("void", $3)}
type : primitivetype { $1 } type : primitivetype { $1 }
-- | referencetype { } | referencetype { $1 }
variabledeclarators : variabledeclarator { [$1] } variabledeclarators : variabledeclarator { [$1] }
-- | variabledeclarators COMMA variabledeclarator { $1 ++ [$3] } | variabledeclarators COMMA variabledeclarator { $1 ++ [$3] }
methodbody : block { } methodbody : block { $1 }
| SEMICOLON { } | SEMICOLON { Block [] }
blockstatements : blockstatement { } blockstatements : blockstatement { $1 }
| blockstatements blockstatement { } | blockstatements blockstatement { $1 ++ $2}
formalparameterlist : formalparameter { } formalparameterlist : formalparameter { [$1] }
| formalparameterlist COMMA formalparameter{ } | formalparameterlist COMMA formalparameter { $1 ++ [$3] }
explicitconstructorinvocation : THIS LBRACE RBRACE SEMICOLON { } explicitconstructorinvocation : THIS LBRACE RBRACE SEMICOLON { }
| THIS LBRACE argumentlist RBRACE SEMICOLON { } | THIS LBRACE argumentlist RBRACE SEMICOLON { }
@ -170,22 +173,22 @@ explicitconstructorinvocation : THIS LBRACE RBRACE SEMICOLON { }
classtypelist : classtype { } classtypelist : classtype { }
| classtypelist COMMA classtype { } | classtypelist COMMA classtype { }
methoddeclarator : IDENTIFIER LBRACE RBRACE { } methoddeclarator : IDENTIFIER LBRACE RBRACE { ($1, []) }
| IDENTIFIER LBRACE formalparameterlist RBRACE { } | IDENTIFIER LBRACE formalparameterlist RBRACE { ($1, $3) }
primitivetype : BOOLEAN { "boolean" } primitivetype : BOOLEAN { "boolean" }
| numerictype { $1 } | numerictype { $1 }
referencetype : classorinterfacetype { } referencetype : classorinterfacetype { $1 }
variabledeclarator : variabledeclaratorid { Declarator $1 Nothing } variabledeclarator : variabledeclaratorid { Declarator $1 Nothing }
-- | variabledeclaratorid ASSIGN variableinitializer { Declarator $1 Nothing } -- TODO | variabledeclaratorid ASSIGN variableinitializer { Declarator $1 (Just $3) }
blockstatement : localvariabledeclarationstatement { } blockstatement : localvariabledeclarationstatement { $1 }
| statement { } | statement { $1 }
formalparameter : type variabledeclaratorid { } formalparameter : type variabledeclaratorid { ParameterDeclaration $1 $2 }
argumentlist : expression { } argumentlist : expression { }
| argumentlist COMMA expression { } | argumentlist COMMA expression { }
@ -194,27 +197,27 @@ numerictype : integraltype { $1 }
variabledeclaratorid : IDENTIFIER { $1 } variabledeclaratorid : IDENTIFIER { $1 }
variableinitializer : expression { } variableinitializer : expression { $1 }
localvariabledeclarationstatement : localvariabledeclaration SEMICOLON { } localvariabledeclarationstatement : localvariabledeclaration SEMICOLON { $1 }
statement : statementwithouttrailingsubstatement{ } statement : statementwithouttrailingsubstatement{ $1 }
| ifthenstatement { } -- | ifthenstatement { }
| ifthenelsestatement { } -- | ifthenelsestatement { }
| whilestatement { } -- | whilestatement { }
expression : assignmentexpression { } expression : assignmentexpression { $1 }
integraltype : INT { "int" } integraltype : INT { "int" }
| CHAR { "char" } | CHAR { "char" }
localvariabledeclaration : type variabledeclarators { } localvariabledeclaration : type variabledeclarators { map LocalVariableDeclaration $ map (convertDeclarator $1) $2 }
statementwithouttrailingsubstatement : block { } statementwithouttrailingsubstatement : block { [$1] }
| emptystatement { } | emptystatement { [] }
| expressionstatement { } -- | expressionstatement { }
| returnstatement { } -- | returnstatement { }
ifthenstatement : IF LBRACE expression RBRACE statement { } ifthenstatement : IF LBRACE expression RBRACE statement { }
@ -222,10 +225,10 @@ ifthenelsestatement : IF LBRACE expression RBRACE statementnoshortif ELSE state
whilestatement : WHILE LBRACE expression RBRACE statement { } whilestatement : WHILE LBRACE expression RBRACE statement { }
assignmentexpression : conditionalexpression { } assignmentexpression : conditionalexpression { $1 }
| assignment{ } -- | assignment { }
emptystatement : SEMICOLON { } emptystatement : SEMICOLON { Block [] }
expressionstatement : statementexpression SEMICOLON { } expressionstatement : statementexpression SEMICOLON { }
@ -236,10 +239,10 @@ statementnoshortif : statementwithouttrailingsubstatement { }
| ifthenelsestatementnoshortif { } | ifthenelsestatementnoshortif { }
| whilestatementnoshortif { } | whilestatementnoshortif { }
conditionalexpression : conditionalorexpression { } conditionalexpression : conditionalorexpression { $1 }
| conditionalorexpression QUESMARK expression COLON conditionalexpression { } -- | conditionalorexpression QUESMARK expression COLON conditionalexpression { }
assignment :lefthandside assignmentoperator assignmentexpression { } assignment : lefthandside assignmentoperator assignmentexpression { }
statementexpression : assignment { } statementexpression : assignment { }
@ -255,23 +258,23 @@ ifthenelsestatementnoshortif :IF LBRACE expression RBRACE statementnoshortif
whilestatementnoshortif : WHILE LBRACE expression RBRACE statementnoshortif { } whilestatementnoshortif : WHILE LBRACE expression RBRACE statementnoshortif { }
conditionalorexpression : conditionalandexpression { } conditionalorexpression : conditionalandexpression { $1 }
| conditionalorexpression LOGICALOR conditionalandexpression{ } -- | conditionalorexpression LOGICALOR conditionalandexpression{ }
lefthandside : name { } lefthandside : name { $1 }
assignmentoperator : ASSIGN{ } assignmentoperator : ASSIGN{ }
| TIMESEQUAL { } -- | TIMESEQUAL { }
| DIVIDEEQUAL { } -- | DIVIDEEQUAL { }
| MODULOEQUAL { } -- | MODULOEQUAL { }
| PLUSEQUAL { } -- | PLUSEQUAL { }
| MINUSEQUAL { } -- | MINUSEQUAL { }
| SHIFTLEFTEQUAL { } -- | SHIFTLEFTEQUAL { }
| SIGNEDSHIFTRIGHTEQUAL { } -- | SIGNEDSHIFTRIGHTEQUAL { }
| UNSIGNEDSHIFTRIGHTEQUAL { } -- | UNSIGNEDSHIFTRIGHTEQUAL { }
| ANDEQUAL { } -- | ANDEQUAL { }
| XOREQUAL { } -- | XOREQUAL { }
| OREQUAL{ } -- | OREQUAL{ }
preincrementexpression : INCREMENT unaryexpression { } preincrementexpression : INCREMENT unaryexpression { }
@ -289,73 +292,73 @@ methodinvocation : name LBRACE RBRACE { }
classinstancecreationexpression : NEW classtype LBRACE RBRACE { } classinstancecreationexpression : NEW classtype LBRACE RBRACE { }
| NEW classtype LBRACE argumentlist RBRACE { } | NEW classtype LBRACE argumentlist RBRACE { }
conditionalandexpression : inclusiveorexpression { } conditionalandexpression : inclusiveorexpression { $1 }
fieldaccess : primary DOT IDENTIFIER { } fieldaccess : primary DOT IDENTIFIER { }
unaryexpression : preincrementexpression { } unaryexpression : unaryexpressionnotplusminus { $1 }
| predecrementexpression { } -- | predecrementexpression { }
| PLUS unaryexpression { } -- | PLUS unaryexpression { }
| MINUS unaryexpression { } -- | MINUS unaryexpression { }
| unaryexpressionnotplusminus { } -- | preincrementexpression { $1 }
postfixexpression : primary { } postfixexpression : primary { $1 }
| name { } -- | name { }
| postincrementexpression { } -- | postincrementexpression { }
| postdecrementexpression{ } -- | postdecrementexpression{ }
primary : primarynonewarray { } primary : primarynonewarray { $1 }
inclusiveorexpression : exclusiveorexpression { } inclusiveorexpression : exclusiveorexpression { $1 }
| inclusiveorexpression OR exclusiveorexpression { } -- | inclusiveorexpression OR exclusiveorexpression { }
primarynonewarray : literal { } primarynonewarray : literal { $1 }
| THIS { } -- | THIS { }
| LBRACE expression RBRACE { } -- | LBRACE expression RBRACE { }
| classinstancecreationexpression { } -- | classinstancecreationexpression { }
| fieldaccess { } -- | fieldaccess { }
| methodinvocation { } -- | methodinvocation { }
unaryexpressionnotplusminus : postfixexpression { } unaryexpressionnotplusminus : postfixexpression { $1 }
| TILDE unaryexpression { } -- | TILDE unaryexpression { }
| EXCLMARK unaryexpression { } -- | EXCLMARK unaryexpression { }
| castexpression{ } -- | castexpression{ }
exclusiveorexpression : andexpression { } exclusiveorexpression : andexpression { $1 }
| exclusiveorexpression XOR andexpression { } -- | exclusiveorexpression XOR andexpression { }
literal : INTLITERAL { } literal : INTLITERAL { IntegerLiteral $1 }
| BOOLLITERAL { } | BOOLLITERAL { BooleanLiteral $1 }
| CHARLITERAL { } | CHARLITERAL { CharacterLiteral $1 }
| JNULL { } | JNULL { NullLiteral }
castexpression : LBRACE primitivetype RBRACE unaryexpression { } castexpression : LBRACE primitivetype RBRACE unaryexpression { }
| LBRACE expression RBRACE unaryexpressionnotplusminus{ } | LBRACE expression RBRACE unaryexpressionnotplusminus{ }
andexpression : equalityexpression { } andexpression : equalityexpression { $1 }
| andexpression AND equalityexpression { } -- | andexpression AND equalityexpression { }
equalityexpression : relationalexpression { } equalityexpression : relationalexpression { $1 }
| equalityexpression EQUAL relationalexpression { } -- | equalityexpression EQUAL relationalexpression { }
| equalityexpression NOTEQUAL relationalexpression { } -- | equalityexpression NOTEQUAL relationalexpression { }
relationalexpression : shiftexpression { } relationalexpression : shiftexpression { $1 }
| relationalexpression LESS shiftexpression { } -- | relationalexpression LESS shiftexpression { }
| relationalexpression GREATER shiftexpression { } -- | relationalexpression GREATER shiftexpression { }
| relationalexpression LESSEQUAL shiftexpression { } -- | relationalexpression LESSEQUAL shiftexpression { }
| relationalexpression GREATEREQUAL shiftexpression { } -- | relationalexpression GREATEREQUAL shiftexpression { }
| relationalexpression INSTANCEOF referencetype { } -- | relationalexpression INSTANCEOF referencetype { }
shiftexpression : additiveexpression { } shiftexpression : additiveexpression { $1 }
additiveexpression : multiplicativeexpression { } additiveexpression : multiplicativeexpression { $1 }
| additiveexpression PLUS multiplicativeexpression { } -- | additiveexpression PLUS multiplicativeexpression { }
| additiveexpression MINUS multiplicativeexpression { } -- | additiveexpression MINUS multiplicativeexpression { }
multiplicativeexpression : unaryexpression { } multiplicativeexpression : unaryexpression { $1 }
| multiplicativeexpression MUL unaryexpression { } -- | multiplicativeexpression MUL unaryexpression { }
| multiplicativeexpression DIV unaryexpression { } -- | multiplicativeexpression DIV unaryexpression { }
| multiplicativeexpression MOD unaryexpression { } -- | multiplicativeexpression MOD unaryexpression { }
{ {
@ -365,13 +368,10 @@ data MethodOrFieldDeclaration = MethodDecl MethodDeclaration
data Declarator = Declarator Identifier (Maybe Expression) data Declarator = Declarator Identifier (Maybe Expression)
-- convertDeclaratorList :: [DataType] -> MethodOrFieldDeclaration
-- convertDeclaratorList = FieldDecls $ map
convertDeclarator :: DataType -> Declarator -> VariableDeclaration convertDeclarator :: DataType -> Declarator -> VariableDeclaration
convertDeclarator dataType (Declarator id assigment) = VariableDeclaration dataType id assigment convertDeclarator dataType (Declarator id assigment) = VariableDeclaration dataType id assigment
parseError :: [Token] -> a parseError :: ([Token], [String]) -> a
parseError msg = error ("Parse error: " ++ show msg) parseError (errortoken, expected) = error ("parse error on token: " ++ show errortoken ++ "\nexpected one of: " ++ show expected)
} }