Compare commits

..

No commits in common. "9d7af6effbafb0d8aaeb17a3b31cd9fcb9bd5f7a" and "7cbf8aad08cd65eec959db0537b269677fdca548" have entirely different histories.

2 changed files with 130 additions and 210 deletions

View File

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