Related articles |
---|
Conflicts extending grammar g.wagenknecht@planet-wagenknecht.de (Gunnar Wagenknecht) (2003-03-09) |
From: | "Gunnar Wagenknecht" <g.wagenknecht@planet-wagenknecht.de> |
Newsgroups: | comp.compilers |
Date: | 9 Mar 2003 17:13:26 -0500 |
Organization: | T-Online |
Keywords: | parse, question |
Posted-Date: | 09 Mar 2003 17:13:26 EST |
Hi!
I have a grammar writen for the xBase programming language "Harbour"
(Clipper). But it is only written for recognizing Harbour source after
it was preprocessed. I need to build a DOM of Harbour source files
which are not preprocessed. Thus, I started adding rules for
recognizing preprocessor directives and comments.
The problem I have now is related to the recognizing of "command
calls" and to distinguish them from function calls if possible. I
added a rule around line 244 in the grammar file but as soon as I use
it, I got a some shift/reduce and reduce/reduce conflicts. The grammar
is written for "Jay" (a Yacc for Java).
Command calls are normaly replaced by the preprocessor to function
calls and other statements. Thus, they don't exsit in the final source
the compiler gets. But I need to build a full detailed DOM because I
want to build an editor that will alow refactoring and other nice
features later is has a DOM to play with.
Abstract:
I have statements.
Statement : ExecFlow Crlf
| WithObject Crlf
| FunCall Crlf // function calls <<<<<<<<
| Commands Crlf // command calls <<<<<<<<
| AliasExpr Crlf
| ObjectMethod Crlf
| WithMethod Crlf
| MacroVar Crlf
| MacroExpr Crlf
| PareExpList Crlf
| ExprPreOp Crlf
| ExprPostOp Crlf
| ExprOperEq Crlf
| ExprEqual Crlf
| ExprAssign Crlf
| DoProc Crlf
| BREAK Crlf
| BREAK Expression Crlf
| RETURN Crlf
| RETURN Expression Crlf
| PUBLIC ExtVarList Crlf
| PRIVATE ExtVarList Crlf
| EXIT Crlf
| LOOP Crlf
| EXTERN ExtList Crlf
| ANNOUNCE IdentName Crlf
;
/* commands
*/
Commands : IdentName ArgList
| Commands IdentName ArgList
;
/* Function call
*/
FunCall : IdentName '(' ArgList ')'
| MacroVar '(' ArgList ')'
| MacroExpr '(' ArgList ')'
| IIFInline
;
ArgList : Argument
| ArgList ',' Argument
;
Argument : EmptyExpression
| VarRef
| AliasVarRef
| FunRef
;
I think one problem in the "Commands" rule is related to the "ArgList" rule
which can match to a single "EmptyExpression" that might be a parenthesized
expression.
Example: function call "myFunction( <expression> )" and command call
"myCommand <parenthesizedExpression>"
As a workaround I thought of throwing away the different between function
and command calls and handle them all as function calls. But if I remove the
"Commands" rule and modify the "FunCall" rule I also get shift/reduce and
reduce/reduce conflicts.
Cu, Gunnar
Return to the
comp.compilers page.
Search the
comp.compilers archives again.