LL(1) problem

"Albert" <albert@shqiperia.com>
27 Apr 2003 02:22:06 -0400

          From comp.compilers

Related articles
LL(1) problem albert@shqiperia.com (Albert) (2003-04-27)
Re: LL(1) problem cdc25@it.canterbury.ac.nz (Carl Cerecke) (2003-05-05)
Re: LL(1) problem vbdis@aol.com (2003-05-05)
Re: LL(1) problem slk15@earthlink.net (SLK Parsers) (2003-05-06)
| List of all articles for this month |

From: "Albert" <albert@shqiperia.com>
Newsgroups: comp.compilers
Date: 27 Apr 2003 02:22:06 -0400
Organization: Compilers Central
Keywords: parse, question
Posted-Date: 27 Apr 2003 02:22:05 EDT

Hello guys!
I'm working for a simple recursive decent parsing compiler for .NET. I
have written a EBNF grammar for my language and I'm using Coco/R to
generate the parser and the scanner. I have a problem for one of my
productions witch isn't LL(1). I have tried several times to correct it,
but unsuccessfully :(
Essentially the problem is that in an expression a factor can be a
identifier(variable) or can be a field of a class(ident.ident). Please
can anyone help me to resolve this.
Best Regards, Albert




This is the EBNF grammar:


COMPILER Matrix
CHARACTERS
    letter = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".
    digit = "0123456789".
    cr = '\r'.
    lf = '\n'.
    tab = '\t'.
TOKENS
    ident = letter {letter | digit}.
    int = digit { digit }.
IGNORE cr + lf + tab
COMMENTS FROM "/*" TO "*/" NESTED
PRODUCTIONS
Matrix = "pakete" PackageName "{" ClassDeclaration {ClassDeclaration}
"}".
PackageName = ident ":" ident { ":" ident }.
ClassDeclaration = "klase" [ClassVisibilityModifier]
[ClassAccessModifier] ident ["trashegon" ClassName]
  ["implementon" ClassName] "{" {FieldDeclaration} "}".
FieldDeclaration = MethodDeclaration | ConstructorDeclaration |
VariableDeclaration.
ClassVisibilityModifier = "privat" | "publik".
ClassAccessModifier = "abstrakt" | "final".
ClassName = [PackageName] "." ident .
MethodDeclaration = "metode" [MemberAccessModifier] ident "("
[ParameterList] ")" "kthen" Type StatementBlock.
MemberAccessModifier = "privat" | ("i" "mbrojtur") | "publik" [ "statik"
].
ParameterList = Parameter {"," Parameter}.
Parameter = Type ident.
ConstructorDeclaration = [MemberAccessModifier] ident "("
[ParameterList] ")" StatementBlock.
VariableDeclaration = "variabel" [MemberAccessModifier] Type ident {","
ident} ";".
StatementBlock = "{" [Statement] "}".
Statement = VariableDeclaration | Expression ";" | StatementBlock |
IfStatement | WhileStatement
  | ("kthe" [Expression] ";") | ("krijo" ( ClassName "(" [ ArgList ]
")" )) | ReadStatement | WriteStatement.
ReadStatement = "lexo" ident { "," ident } ";".
WriteStatement = "shkruaj" ArgList ";".
Expression = RelationalExpression { ("&&" | "||") RelationalExpression
}.
RelationalExpression = AssingExpression [ (">" | ">=" | "<" | "<=" |
"==" | "!=") AssingExpression].
AssingExpression = SimpleExpression {"=" SimpleExpression}.
SimpleExpression = Term { ("+" | "-") Term }.
Term = Factor { ("*" | "/" | "%" ) Factor}.
Factor = LogicalConstant | LiteralExpression | MemberAccess | ident |
"(" Expression ")" | "bosh".
MemberAccess = (ClassName | "ky") "." ident [ "(" [ArgList] ")" ].
LogicalConstant = "i" ("vertete" | "gabuar").
LiteralExpression = NumberLiteral | String | Character.
ArgList = Expression { "," Expression }.
NumberLiteral = ("+" | "-") int ["." int].
String = "\"" { ANY } "\"".
Character = "'" ANY "'".
IfStatement = "nqs" "(" Expression ")" Statement [ "pnd" Statement ]
.
WhileStatement = "perderisa" "(" Expression ")" Statement .
Type = "byte" | "int" | "real" | "logjik" | "karakter" | "string" |
ClassName.
END Matrix.


Imagination is more important than knowledge
Albert Tollkuçi


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.