?prevdifflink? - Blame
-- This Happy file was machine-generated by the BNF converter
{
{-# OPTIONS -fno-warn-incomplete-patterns -fno-warn-overlapping-patterns #-}
module Parjava where
import Absjava
import Lexjava
import ErrM
}
%name pProgramFile ProgramFile
-- no lexer declaration
%monad { Err } { thenM } { returnM }
%tokentype { Token }
%token
'.*' { PT _ (TS ".*") }
'{' { PT _ (TS "{") }
'}' { PT _ (TS "}") }
';' { PT _ (TS ";") }
'(' { PT _ (TS "(") }
')' { PT _ (TS ")") }
':' { PT _ (TS ":") }
'=' { PT _ (TS "=") }
',' { PT _ (TS ",") }
'else if' { PT _ (TS "else if") }
'[]' { 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 "<=") }
'>=' { 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 "]") }
'.this' { PT _ (TS ".this") }
'.class' { PT _ (TS ".class") }
'~' { 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 "|=") }
'abstract' { PT _ (TS "abstract") }
'boolean' { PT _ (TS "boolean") }
'break' { PT _ (TS "break") }
'byte' { PT _ (TS "byte") }
'case' { PT _ (TS "case") }
'catch' { PT _ (TS "catch") }
'char' { PT _ (TS "char") }
'class' { PT _ (TS "class") }
'continue' { PT _ (TS "continue") }
'default' { PT _ (TS "default") }
'do' { PT _ (TS "do") }
'double' { PT _ (TS "double") }
'else' { PT _ (TS "else") }
'extends' { PT _ (TS "extends") }
'false' { PT _ (TS "false") }
'final' { PT _ (TS "final") }
'finally' { PT _ (TS "finally") }
'float' { PT _ (TS "float") }
'for' { PT _ (TS "for") }
'if' { PT _ (TS "if") }
'implements' { PT _ (TS "implements") }
'import' { PT _ (TS "import") }
'instanceof' { PT _ (TS "instanceof") }
'int' { PT _ (TS "int") }
'interface' { PT _ (TS "interface") }
'long' { PT _ (TS "long") }
'native' { PT _ (TS "native") }
'new' { PT _ (TS "new") }
'null' { PT _ (TS "null") }
'package' { PT _ (TS "package") }
'private' { PT _ (TS "private") }
'protected' { PT _ (TS "protected") }
'public' { PT _ (TS "public") }
'return' { PT _ (TS "return") }
'short' { PT _ (TS "short") }
'static' { PT _ (TS "static") }
'super' { PT _ (TS "super") }
'switch' { PT _ (TS "switch") }
'synchronized' { PT _ (TS "synchronized") }
'this' { PT _ (TS "this") }
'throw' { PT _ (TS "throw") }
'throws' { PT _ (TS "throws") }
'transient' { PT _ (TS "transient") }
'true' { PT _ (TS "true") }
'try' { PT _ (TS "try") }
'volatile' { PT _ (TS "volatile") }
'while' { PT _ (TS "while") }
L_ident { PT _ (TV $$) }
L_quoted { PT _ (TL $$) }
L_doubl { PT _ (TD $$) }
L_integ { PT _ (TI $$) }
L_Unsigned { PT _ (T_Unsigned $$) }
L_Long { PT _ (T_Long $$) }
L_UnsignedLong { PT _ (T_UnsignedLong $$) }
L_Hexadecimal { PT _ (T_Hexadecimal $$) }
L_HexUnsigned { PT _ (T_HexUnsigned $$) }
L_HexLong { PT _ (T_HexLong $$) }
L_HexUnsLong { PT _ (T_HexUnsLong $$) }
L_Octal { PT _ (T_Octal $$) }
L_OctalUnsigned { PT _ (T_OctalUnsigned $$) }
L_OctalLong { PT _ (T_OctalLong $$) }
L_OctalUnsLong { PT _ (T_OctalUnsLong $$) }
L_JDouble { PT _ (T_JDouble $$) }
L_JFloat { PT _ (T_JFloat $$) }
L_JLongDouble { PT _ (T_JLongDouble $$) }
L_UnicodeChar { PT _ (T_UnicodeChar $$) }
L_JChar { PT _ (T_JChar $$) }
L_err { _ }
%%
Ident :: { Ident } : L_ident { Ident $1 }
String :: { String } : L_quoted { $1 }
Double :: { Double } : L_doubl { (read $1) :: Double }
Integer :: { Integer } : L_integ { (read $1) :: Integer }
Unsigned :: { Unsigned} : L_Unsigned { Unsigned ($1)}
Long :: { Long} : L_Long { Long ($1)}
UnsignedLong :: { UnsignedLong} : L_UnsignedLong { UnsignedLong ($1)}
Hexadecimal :: { Hexadecimal} : L_Hexadecimal { Hexadecimal ($1)}
HexUnsigned :: { HexUnsigned} : L_HexUnsigned { HexUnsigned ($1)}
HexLong :: { HexLong} : L_HexLong { HexLong ($1)}
HexUnsLong :: { HexUnsLong} : L_HexUnsLong { HexUnsLong ($1)}
Octal :: { Octal} : L_Octal { Octal ($1)}
OctalUnsigned :: { OctalUnsigned} : L_OctalUnsigned { OctalUnsigned ($1)}
OctalLong :: { OctalLong} : L_OctalLong { OctalLong ($1)}
OctalUnsLong :: { OctalUnsLong} : L_OctalUnsLong { OctalUnsLong ($1)}
JDouble :: { JDouble} : L_JDouble { JDouble ($1)}
JFloat :: { JFloat} : L_JFloat { JFloat ($1)}
JLongDouble :: { JLongDouble} : L_JLongDouble { JLongDouble ($1)}
UnicodeChar :: { UnicodeChar} : L_UnicodeChar { UnicodeChar ($1)}
JChar :: { JChar} : L_JChar { JChar ($1)}
ProgramFile :: { ProgramFile }
ProgramFile : 'package' ListIdent ListSemi ListImport ListTypeDecl { Prpkg $2 (reverse $3) (reverse $4) (reverse $5) }
| ListImport ListTypeDecl { ProgF (reverse $1) (reverse $2) }
Import :: { Import }
Import : 'import' ListIdent ListSemi { ImportN $2 (reverse $3) }
| 'import' ListIdent '.*' ListSemi { ImportA $2 (reverse $4) }
ListImport :: { [Import] }
ListImport : {- empty -} { [] }
| ListImport Import { flip (:) $1 $2 }
TypeDecl :: { TypeDecl }
TypeDecl : ClassHeader '{' ListFieldDeclaration '}' { TypeDecl $1 (reverse $3) }
ListTypeDecl :: { [TypeDecl] }
ListTypeDecl : {- empty -} { [] }
| ListTypeDecl TypeDecl { flip (:) $1 $2 }
ClassHeader :: { ClassHeader }
ClassHeader : ListModifier 'class' Ident { ClassDec (reverse $1) $3 }
| ListModifier 'class' Ident 'extends' ListTypeName { ClassDecE (reverse $1) $3 $5 }
| ListModifier 'class' Ident 'implements' ListTypeName { ClassDecI (reverse $1) $3 $5 }
| ListModifier 'class' Ident 'extends' ListTypeName 'implements' ListTypeName { ClassDecEI (reverse $1) $3 $5 $7 }
| ListModifier 'interface' Ident { InterDec (reverse $1) $3 }
| ListModifier 'interface' Ident 'extends' ListTypeName { InterDecE (reverse $1) $3 $5 }
| ListModifier 'interface' Ident 'implements' ListTypeName { InterDecI (reverse $1) $3 $5 }
| ListModifier 'interface' Ident 'extends' ListTypeName 'implements' ListTypeName { InterDecEI (reverse $1) $3 $5 $7 }
FieldDeclaration :: { FieldDeclaration }
FieldDeclaration : ListModifier TypeSpec ListVarDecl ';' { Dvar (reverse $1) $2 $3 }
| ListModifier TypeSpec MethodDecl MethodBody { Dmth (reverse $1) $2 $3 $4 }
| ListModifier TypeSpec MethodDecl 'throws' ListTypeName MethodBody { Dmthth (reverse $1) $2 $3 $5 $6 }
| ListModifier Ident '(' ListParameter ')' Body { Dconst (reverse $1) $2 $4 $6 }
| ListModifier Ident '(' ListParameter ')' 'throws' ListTypeName Body { Dconstt (reverse $1) $2 $4 $7 $8 }
| Body { Dblk $1 }
| TypeDecl { Dinnerclass $1 }
ListFieldDeclaration :: { [FieldDeclaration] }
ListFieldDeclaration : {- empty -} { [] }
| ListFieldDeclaration FieldDeclaration { flip (:) $1 $2 }
MethodBody :: { MethodBody }
MethodBody : ';' { IBody }
| Body { MBody $1 }
LVarStatement :: { LVarStatement }
LVarStatement : TypeSpec ListVarDecl ';' { LVar $1 $2 }
| 'final' TypeSpec ListVarDecl ';' { LVarf $2 $3 }
| Stm { Statem $1 }
ListLVarStatement :: { [LVarStatement] }
ListLVarStatement : {- empty -} { [] }
| ListLVarStatement LVarStatement { flip (:) $1 $2 }
Body :: { Body }
Body : '{' ListLVarStatement '}' { Body (reverse $2) }
Stm :: { Stm }
Stm : ';' { Sem }
| Ident ':' { Lbl $1 }
| 'case' Exp ':' { Case $2 }
| 'default' ':' { Dflt }
| Exp ';' { Exps $1 }
| '{' ListLVarStatement '}' { LV (reverse $2) }
| JumpStm { Jmp $1 }
| GuardStm { Grd $1 }
| IterStm { Iter $1 }
| SelectionStm { Sel $1 }
DeclaratorName :: { DeclaratorName }
DeclaratorName : Ident { DeclName $1 }
| Ident ListBracketsOpt { DeclArray $1 $2 }
VarDecl :: { VarDecl }
VarDecl : DeclaratorName '=' VariableInits { VDeclAssign $1 $3 }
| Ident { VDecl $1 }
ListVarDecl :: { [VarDecl] }
ListVarDecl : VarDecl { (:[]) $1 }
| VarDecl ',' ListVarDecl { (:) $1 $3 }
VariableInits :: { VariableInits }
VariableInits : Exp { IExp $1 }
| '{' '}' { IEmpt }
| '{' ArrayInits '}' { IArri $2 }
ArrayInits :: { ArrayInits }
ArrayInits : VariableInits { Vainit $1 }
| ArrayInits ',' VariableInits { Vai $1 $3 }
| ArrayInits ',' { Vais $1 }
MethodDecl :: { MethodDecl }
MethodDecl : DeclaratorName '(' ListParameter ')' { Mth $1 $3 }
| MethodDecl BracketsOpt { MthdArr $1 $2 }
Parameter :: { Parameter }
Parameter : TypeSpec DeclaratorName { Param $1 $2 }
| 'final' TypeSpec DeclaratorName { Pfinal $2 $3 }
ListParameter :: { [Parameter] }
ListParameter : {- empty -} { [] }
| Parameter { (:[]) $1 }
| Parameter ',' ListParameter { (:) $1 $3 }
SelectionStm :: { SelectionStm }
SelectionStm : 'if' '(' Exp ')' Stm ListElseif { Ifone $3 $5 (reverse $6) }
| 'if' '(' Exp ')' Stm ListElseif 'else' Stm { If $3 $5 (reverse $6) $8 }
| 'switch' '(' Exp ')' Body { Switch $3 $5 }
Elseif :: { Elseif }
Elseif : 'else if' '(' Exp ')' Stm { Elseif $3 $5 }
ListElseif :: { [Elseif] }
ListElseif : {- empty -} { [] }
| ListElseif Elseif { flip (:) $1 $2 }
JumpStm :: { JumpStm }
JumpStm : 'break' ';' { Break }
| 'break' Ident ';' { Brlabel $2 }
| 'continue' ';' { Continue }
| 'continue' Ident ';' { Continuelabel $2 }
| 'return' ';' { Return }
| 'return' Exp ';' { ReturnExp $2 }
| 'throw' Exp ';' { Throw $2 }
GuardStm :: { GuardStm }
GuardStm : 'synchronized' '(' Exp ')' Body { Synchronized $3 $5 }
| 'try' Body ListCatch { Try $2 (reverse $3) }
| 'try' Body ListCatch 'finally' Body { Tryfinally $2 (reverse $3) $5 }
Catch :: { Catch }
Catch : 'catch' '(' TypeSpec Ident ')' Body { Catch1 $3 $4 $6 }
| 'catch' '(' TypeSpec ')' Body { Catch2 $3 $5 }
ListCatch :: { [Catch] }
ListCatch : {- empty -} { [] }
| ListCatch Catch { flip (:) $1 $2 }
IterStm :: { IterStm }
IterStm : 'while' '(' Exp ')' Stm { While $3 $5 }
| 'do' Stm 'while' '(' Exp ')' { Do $2 $5 }
| 'for' '(' ForInit ListExp ';' ListExp ')' Stm { For $3 $4 $6 $8 }
ForInit :: { ForInit }
ForInit : ListExp ';' { Exprs1 $1 }
| TypeSpec ListVarDecl ';' { DVar $1 $2 }
| 'final' TypeSpec ListVarDecl ';' { DVarf $2 $3 }
Modifier :: { Modifier }
Modifier : 'abstract' { Mabstract }
| 'final' { Mfinal }
| 'public' { Mpublic }
| 'protected' { Mprotected }
| 'private' { Mprivate }
| 'transient' { Mtransient }
| 'volatile' { Mvolatile }
| 'native' { Mnative }
| 'synchronized' { Msync }
| 'static' { Mstatic }
ListModifier :: { [Modifier] }
ListModifier : {- empty -} { [] }
| ListModifier Modifier { flip (:) $1 $2 }
BasicType :: { BasicType }
BasicType : 'char' { Tchar }
| 'short' { Tshort }
| 'int' { Tint }
| 'long' { Tlong }
| 'float' { Tfloat }
| 'double' { Tdouble }
| 'byte' { Tbyte }
| 'boolean' { Tboolean }
TypeSpec :: { TypeSpec }
TypeSpec : TypeName ListBracketsOpt { ArrayType $1 $2 }
| TypeName { TypeName $1 }
TypeName :: { TypeName }
TypeName : BasicType { BuiltIn $1 }
| ListIdent { ClassType $1 }
ListTypeName :: { [TypeName] }
ListTypeName : TypeName { (:[]) $1 }
| TypeName ',' ListTypeName { (:) $1 $3 }
BracketsOpt :: { BracketsOpt }
BracketsOpt : '[]' { BracketsOpt }
ListBracketsOpt :: { [BracketsOpt] }
ListBracketsOpt : BracketsOpt { (:[]) $1 }
| BracketsOpt ListBracketsOpt { (:) $1 $2 }
ListIdent :: { [Ident] }
ListIdent : Ident { (:[]) $1 }
| Ident '.' ListIdent { (:) $1 $3 }
Exp :: { Exp }
Exp : Exp14 Assignment_op Exp { Eassign $1 $2 $3 }
| Exp14 'instanceof' TypeName { Etype $1 $3 }
| Exp1 { $1 }
Exp2 :: { Exp }
Exp2 : Exp3 '?' Exp ':' Exp2 { Econdition $1 $3 $5 }
| Exp3 { $1 }
Exp3 :: { Exp }
Exp3 : Exp3 '||' Exp4 { Elor $1 $3 }
| Exp4 { $1 }
Exp4 :: { Exp }
Exp4 : Exp4 '&&' Exp5 { Eland $1 $3 }
| Exp5 { $1 }
Exp5 :: { Exp }
Exp5 : Exp5 '|' Exp6 { Ebitor $1 $3 }
| Exp6 { $1 }
Exp6 :: { Exp }
Exp6 : Exp6 '^' Exp7 { Ebitexor $1 $3 }
| Exp7 { $1 }
Exp7 :: { Exp }
Exp7 : Exp7 '&' Exp8 { Ebitand $1 $3 }
| Exp8 { $1 }
Exp8 :: { Exp }
Exp8 : Exp8 '==' Exp9 { Eeq $1 $3 }
| Exp8 '!=' Exp9 { Eneq $1 $3 }
| Exp9 { $1 }
Exp9 :: { Exp }
Exp9 : Exp9 '<' Exp10 { Elthen $1 $3 }
| Exp9 '>' Exp10 { Egrthen $1 $3 }
| Exp9 '<=' Exp10 { Ele $1 $3 }
| Exp9 '>=' Exp10 { Ege $1 $3 }
| Exp10 { $1 }
Exp10 :: { Exp }
Exp10 : Exp10 '<<' Exp11 { Eleft $1 $3 }
| Exp10 '>>' Exp11 { Eright $1 $3 }
| Exp10 '>>>' Exp11 { Etrip $1 $3 }
| Exp11 { $1 }
Exp11 :: { Exp }
Exp11 : Exp11 '+' Exp12 { Eplus $1 $3 }
| Exp11 '-' Exp12 { Eminus $1 $3 }
| Exp12 { $1 }
Exp12 :: { Exp }
Exp12 : Exp12 '*' Exp13 { Etimes $1 $3 }
| Exp12 '/' Exp13 { Ediv $1 $3 }
| Exp12 '%' Exp13 { Emod $1 $3 }
| Exp13 { $1 }
Exp13 :: { Exp }
Exp13 : '(' BasicType ')' Exp13 { Ebcoercion $2 $4 }
| '(' Exp ')' Exp15 { Eexpcoercion $2 $4 }
| '(' ListIdent ListBracketsOpt ')' Exp13 { Earrcoercion $2 $3 $5 }
| Exp14 { $1 }
Exp14 :: { Exp }
Exp14 : Unary_operator Exp13 { Epreop $1 $2 }
| '++' Exp14 { Epreinc $2 }
| '--' Exp14 { Epredec $2 }
| Exp15 { $1 }
Exp15 :: { Exp }
Exp15 : Exp15 '++' { Epostinc $1 }
| Exp15 '--' { Epostdec $1 }
| Exp16 { $1 }
Exp16 :: { Exp }
Exp16 : SpecName { Especname $1 }
| ArrAcc { Earr $1 }
| MthCall { Emth $1 }
| FieldAcc { Efld $1 }
| Constant { Econst $1 }
| String { Estring $1 }
| Exp17 { $1 }
Exp17 :: { Exp }
Exp17 : NewAlloc { Enewalloc $1 }
| Exp18 { $1 }
Exp18 :: { Exp }
Exp18 : ListIdent { Evar $1 }
| '(' Exp ')' { $2 }
SpecName :: { SpecName }
SpecName : 'super' { SSsuper }
| 'this' { SSthis }
| 'null' { SSnull }
NewAlloc :: { NewAlloc }
NewAlloc : 'new' TypeName Args { Anewclass $2 $3 }
| 'new' TypeName Args '{' ListFieldDeclaration '}' { Anewinnerclass $2 $3 (reverse $5) }
| 'new' TypeName ListDimExpr { Anewarray $2 $3 }
| 'new' TypeName ListDimExpr '{' '}' { Anewarriempty $2 $3 }
| 'new' TypeName ListDimExpr '{' ArrayInits '}' { Anewarrinits $2 $3 $5 }
ArrAcc :: { ArrAcc }
ArrAcc : ListIdent '[' Exp ']' { Aarr $1 $3 }
| SpecExp '[' Exp ']' { Aarr1 $1 $3 }
SpecExp :: { SpecExp }
SpecExp : '(' Exp ')' { Cep $2 }
| SpecExpNP { Cnp $1 }
| SpecName { Cthis $1 }
SpecExpNP :: { SpecExpNP }
SpecExpNP : Constant { CNLit $1 }
| ArrAcc { CNParr $1 }
| MthCall { CNPmth $1 }
| FieldAcc { CNPfld $1 }
MthCall :: { MthCall }
MthCall : ListIdent Args { Mmth $1 $2 }
| SpecExpNP Args { Mmth1 $1 $2 }
| SpecName Args { Mmthspec $1 $2 }
FieldAcc :: { FieldAcc }
FieldAcc : SpecExp '.' Ident { Ffvar $1 $3 }
| NewAlloc '.' Ident { Ffvar1 $1 $3 }
| ListIdent '.this' { Ffthis $1 }
| ListIdent '.class' { Fclass $1 }
| BasicType '.class' { Ffclass2 $1 }
Args :: { Args }
Args : '(' ListExp ')' { Args $2 }
DimExpr :: { DimExpr }
DimExpr : '[' Exp ']' { DimExpr $2 }
ListDimExpr :: { [DimExpr] }
ListDimExpr : DimExpr { (:[]) $1 }
| DimExpr ListDimExpr { (:) $1 $2 }
ListExp :: { [Exp] }
ListExp : {- empty -} { [] }
| Exp { (:[]) $1 }
| Exp ',' ListExp { (:) $1 $3 }
Exp1 :: { Exp }
Exp1 : Exp2 { $1 }
Constant :: { Constant }
Constant : Double { Efloat $1 }
| JChar { Echar $1 }
| UnicodeChar { Eunicode $1 }
| Unsigned { Eunsigned $1 }
| Long { Elong $1 }
| UnsignedLong { Eunsignlong $1 }
| Hexadecimal { Ehexadec $1 }
| HexUnsigned { Ehexaunsign $1 }
| HexLong { Ehexalong $1 }
| HexUnsLong { Ehexaunslong $1 }
| Octal { Eoctal $1 }
| OctalUnsigned { Eoctalunsign $1 }
| OctalLong { Eoctallong $1 }
| OctalUnsLong { Eoctalunslong $1 }
| JDouble { Ecdouble $1 }
| JFloat { Ecfloat $1 }
| JLongDouble { Eclongdouble $1 }
| Integer { Eint $1 }
| 'true' { Etrue }
| 'false' { Efalse }
Unary_operator :: { Unary_operator }
Unary_operator : '+' { Plus }
| '-' { Negative }
| '~' { Complement }
| '!' { Logicalneg }
Assignment_op :: { Assignment_op }
Assignment_op : '=' { Assign }
| '*=' { AssignMul }
| '/=' { AssignDiv }
| '%=' { AssignMod }
| '+=' { AssignAdd }
| '-=' { AssignSub }
| '<<=' { AssignLeft }
| '>>=' { AssignRight }
| '>>>=' { AssignTrip }
| '&=' { AssignAnd }
| '^=' { AssignXor }
| '|=' { AssignOr }
Semi :: { Semi }
Semi : ';' { Sem1 }
ListSemi :: { [Semi] }
ListSemi : {- empty -} { [] }
| ListSemi Semi { flip (:) $1 $2 }
{
returnM :: a -> Err a
returnM = return
thenM :: Err a -> (a -> Err b) -> Err b
thenM = (>>=)
happyError :: [Token] -> Err a
happyError ts =
Bad $ "syntax error at " ++ tokenPos ts ++
case ts of
[] -> []
[Err _] -> " due to lexer error"
_ -> " before " ++ unwords (map prToken (take 4 ts))
myLexer = tokens
}
|