Gambit
unread,Mar 17, 2008, 8:47:41 PM3/17/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to GOLD Parsing System
Hello
After some hard time trying to identify and fix two conflicts in a
grammar I´m working on, it seems I realy can´t see the problem. I
guess GOLD Parsers is trying to help me on that, but I can´t
understand. So, I decided to ask for some help here.
There is a shift-reduce conflict and a reduce-reduce conflic. If a
change the rule <Data Type> to not generate Id, the reduce-reduce
conflict is fixed, but the language won´t be what I need. The shitf-
reduce conflict completely scaped from my eyes. I´m stuck and lost.
The grammar is a altered C++ grammar and it is as follows. Any help
will be greatly appreciated.
! -[ Beginning of
Grammar ]-----------------------------------------------------------------------------------------------
"Name" = 'Adapted MS C++'
"Version" = '2008'
"Author" = 'Alex S. Constancio'
"About" = 'Adapted C++ grammar was designed to be used by Gambit API
Workshop for Delphi.'
"Case Sensitive" = True
"Start Symbol" = <Decls>
{Hex Digit} = {Digit} + [abcdefABCDEF]
{Oct Digit} = [01234567]
{Id Head} = {Letter} + [_]
{Id Tail} = {Id Head} + {Digit}
{String Ch} = {Printable} - ["]
{Char Ch} = {Printable} - ['']
DecLiteral = [123456789]{digit}*L?
OctLiteral = 0{Oct Digit}*L?
HexLiteral = 0x{Hex Digit}+L?
FloatLiteral = {Digit}*'.'{Digit}+
StringLiteral = '"'( {String Ch} | '\'{Printable} )* '"'
CharLiteral = '' ( {Char Ch} | '\'{Printable} )''
Id = {Id Head}{Id Tail}*
! ===================================================================
! Comments
! ===================================================================
Comment Start = '/*'
Comment End = '*/'
Comment Line = '//' | '#' error
! Typically, C comments cannot be nested. As a result, the
! Comment Start and Comment End terminals cannot be used.
!
! To implement non-nested comments, the whitespace terminal is
! modified to accept them. In the definition below, Whitespace
! is defined as one or more {Whitespace} characters OR a series
! of characters delimited by /* and */. Note that the characters
! between the two delimiters cannot contain the */ sequence.
!
! Uncomment the following to prevent block commments. Make sure
! to comment the Comment Start and Comment End definitions.
!
! {Non Slash} = {Printable} - [/]
! {Non Asterisk} = {Printable} - [*]
!
! Whitespace = {Whitespace}+
! | '/*' ( {Non Asterisk} | '*' {Non Slash}? )* '*/'
!=======================================================
<Decls> ::= <Decl> <Decls>
|
<Decl> ::= <Enum Decl>
| <Func Decl>
| <Func Proto>
| <Linkage Decl>
| <Struct Decl>
| <Union Decl>
| <Var Decl>
| <Typedef Decl>
| <COMInterface Decl>
| <GUID Decl>
! -[ Enumerations ]---------------------------------------------------
<Enum Decl> ::= enum Id '{' <Enum Items> '}' ';'
<Enum Items> ::= <Enum Item> ',' <Enum Items>
| <Enum Item>
<Enum Item> ::= Id
| Id '=' <Integer Literal>
| Id '=' '(' <Expr> ')'
! ===================================================================
! Function Declaration
! ===================================================================
<Func Sign> ::= <Func Id> '(' <Types> ')'
! | <Func Id> '(' <Params> ')'
| <Func Id> '(' ')'
<Func Proto> ::= <Func Sign> ';'
<Func Decl> ::= <Func Spec> <Func Def>
| <Func Def>
<Func Spec> ::= inline
| explicit
<Func Def> ::= <Func Id> '(' <Params> ')' <Block>
! | <Func Id> '(' <Id List> ')' <Struct Def> <Block>
! | <Func Id> '(' <Id List> ')' <Block>
| <Func Id> '(' ')' <Block>
<Func Call> ::= Id '(' <Argm List> ')'
| Id '(' ')'
<Argm List> ::= <Expr> ',' <Argm List>
| <Expr>
<Params> ::= <Param> ',' <Params>
| <Param>
<Param> ::= <Param Mod> <Param Spec> <Param Def>
| <Param Mod> <Param Def>
| <Param Spec> <Param Def>
| <Param Def>
<Param Def> ::= <Data Type> <Pointer Mod> Id <Array> <Param Value>
| <Data Type> <Pointer Mod> Id <Array>
<Param Value> ::= '=' <Literal Value>
| '=' Id
<Param Spec> ::= const
<Param Mod> ::= __in
| __out
| __in_opt
| __out_opt
| __inout
| __inout_opt
| __in_bcount_opt '(' <Argm List> ')'
| __out_bcount_opt '(' <Argm List> ')'
| __in_range '(' <Argm List> ')'
| __in_ecount '(' <Argm List> ')'
| __out_ecount '(' <Argm List> ')'
| __in_ecount_opt '(' <Argm List> ')'
| __out_ecount_opt '(' <Argm List> ')'
| __in_xcount '(' <Argm List> ')'
| __out_xcount '(' <Argm List> ')'
| __in_xcount_opt '(' <Argm List> ')'
| __out_xcount_opt '(' <Argm List> ')'
<Types> ::= <Type> ',' <Types>
| <Type>
<Func Id> ::= <Func Mod> <Type> Id
! | <Type> <Func Mod> Id
| <Type> Id
| Id
<Func Mod> ::= __stdcall
| STDMETHODCALLTYPE
! ===================================================================
! Linkage Declaration
! ===================================================================
<Linkage Decl> ::= extern StringLiteral '{' <Decls> '}'
! ===================================================================
! Type Declaration
! ===================================================================
<Typedef Decl> ::= typedef <Data Type> <Pointer Mod> Id ';'
<Struct Decl> ::= struct Id <Class Ancestor> <Class Body> ';'
| struct Id <Class Body> ';'
<Union Decl> ::= union Id <Class Body> ';'
<COMInterface Decl> ::= <COMInterface Id> <Class Body> ';'
! ===================================================================
! COM Interface Declaration
! ===================================================================
<COMInterface Id> ::= MIDL_INTERFACE '(' StringLiteral ')' Id <Class
Ancestor>
| MIDL_INTERFACE '(' StringLiteral ')' Id
<Class Ancestor> ::= ':' <Class Visibility> Id
| ':' Id
<Class Body> ::= '{' <Class Members> '}'
<Class Members> ::= <Class Member> <Class Members>
|
<Class Member> ::= <Class Method>
| <Class Data>
| <Member Visibility>
<Class Method> ::= <Abstract Method>
| <Virtual Method>
| <Static Method>
| <Destructor Method>
| <Operator Method>
<SuperClass Method> ::= ':' <Func Call>
|
<Abstract Method> ::= virtual <Method Proto> '=' OctLiteral ';'
<Virtual Method> ::= virtual <Method Proto> <Method Mod> ';'
| virtual <Func Decl>
<Static Method> ::= <Method Def> <SuperClass Method> <Method Mod>
';'
| <Method Def> <SuperClass Method> <Method Mod>
<Block>
<Destructor Method> ::= '~' Id '(' ')' ';'
| '~' Id '(' ')' <Block>
<Operator Method> ::= operator <Operator Mod> <Type> '(' ')' <Method
Mod> ';'
| operator <Operator Mod> <Type> '(' ')' <Method
Mod> <Block>
<Operator Mod> ::= const
|
<Method Def> ::= <Func Spec> <Method Proto>
| <Method Proto>
<Method Mod> ::= volatile
| const
|
<Method Proto> ::= <Func Id> '(' <Params> ')'
| <Func Id> '(' <Types> ')'
| <Func Id> '(' ')'
<Class Data> ::= <Var Decl>
| <Union Data> ';'
<Member Visibility> ::= <Class Visibility> ':'
<Class Visibility> ::= public
| protected
| private
! ===================================================================
! GUID Declaration
! ===================================================================
<GUID Decl> ::= DEFINE_GUID '(' <Argm List> ')' ';'
! ===================================================================
! Variable Declaration
! ===================================================================
<Var Decl> ::= <Mod> <Data Type> <Var> <Var List> ';'
| <Data Type> <Var> <Var List> ';'
! | <Mod> <Var> <Var List> ';'
<Var> ::= <Pointer Mod> Id <Array>
| <Pointer Mod> Id <Array> '=' <Op If>
<Array> ::= '[' <Expr> ']'
| '[' ']'
|
<Var List> ::= ',' <Var> <Var List>
|
<Mod> ::= extern
| static
| register
| auto
| volatile
| const
| EXTERN_C
| EXTERN_C const
! -[ Types ]---------------------------------------------------------
<Type> ::= <Data Type> <Pointer Mod>
<Data Type> ::= <Native Type>
| Id
<Native Type> ::= <Simple Type>
| <Complex Type>
<Complex Type> ::= struct Id
| struct Id <Class Body>
| struct <Class Body>
| enum Id
| enum Id '{' <Enum Items> '}'
| interface Id
| <Union Data>
<Union Data> ::= union Id
| union <Class Body>
<Simple Type> ::= <Sign> <Scalar>
<Sign> ::= signed
| unsigned
|
<Scalar> ::= char
| int
| UINT
| short
| long
| short int
| long int
| float
| double
| void
| RPC_IF_HANDLE
| IID
<Pointer Mod> ::= <Pointer Def> <Pointer Mod>
| '&' <Pointer Mod>
! |
<Pointer Def> ::= '*' const
| '*'
! ===================================================================
! Statements
! ===================================================================
<Stm> ::= <Var Decl>
| Id ':' !Label
| if '(' <Expr> ')' <Stm>
| if '(' <Expr> ')' <Then Stm> else <Stm>
| while '(' <Expr> ')' <Stm>
| for '(' <Arg> ';' <Arg> ';' <Arg> ')' <Stm>
| <Normal Stm>
<Then Stm> ::= if '(' <Expr> ')' <Then Stm> else <Then Stm>
| while '(' <Expr> ')' <Then Stm>
| for '(' <Arg> ';' <Arg> ';' <Arg> ')' <Then Stm>
| <Normal Stm>
<Normal Stm> ::= do <Stm> while '(' <Expr> ')'
| switch '(' <Expr> ')' '{' <Case Stms> '}'
| <Block>
| <Expr> ';'
| goto Id ';'
| break ';'
| continue ';'
| return <Expr> ';'
| ';' !Null statement
<Arg> ::= <Expr>
|
<Case Stms> ::= case <Value> ':' <Stm List> <Case Stms>
| default ':' <Stm List>
|
<Block> ::= '{' <Stm List> '}'
<Stm List> ::= <Stm> <Stm List>
|
! ===================================================================
! Here begins the C's 15 levels of operator precedence.
! ===================================================================
<Expr> ::= <Op Assign>
! | <Expr> ',' <Op Assign>
<Op Assign> ::= <Op If> '=' <Op Assign>
| <Op If> '+=' <Op Assign>
| <Op If> '-=' <Op Assign>
| <Op If> '*=' <Op Assign>
| <Op If> '/=' <Op Assign>
| <Op If> '^=' <Op Assign>
| <Op If> '&=' <Op Assign>
| <Op If> '|=' <Op Assign>
| <Op If> '>>=' <Op Assign>
| <Op If> '<<=' <Op Assign>
| <Op If>
<Op If> ::= <Op Or> '?' <Op If> ':' <Op If>
| <Op Or>
<Op Or> ::= <Op Or> '||' <Op And>
| <Op And>
<Op And> ::= <Op And> '&&' <Op BinOR>
| <Op BinOR>
<Op BinOR> ::= <Op BinOr> '|' <Op BinXOR>
| <Op BinXOR>
<Op BinXOR> ::= <Op BinXOR> '^' <Op BinAND>
| <Op BinAND>
<Op BinAND> ::= <Op BinAND> '&' <Op Equate>
| <Op Equate>
<Op Equate> ::= <Op Equate> '==' <Op Compare>
| <Op Equate> '!=' <Op Compare>
| <Op Compare>
<Op Compare> ::= <Op Compare> '<' <Op Shift>
| <Op Compare> '>' <Op Shift>
| <Op Compare> '<=' <Op Shift>
| <Op Compare> '>=' <Op Shift>
| <Op Shift>
<Op Shift> ::= <Op Shift> '<<' <Op Add>
| <Op Shift> '>>' <Op Add>
| <Op Add>
<Op Add> ::= <Op Add> '+' <Op Mult>
| <Op Add> '-' <Op Mult>
| <Op Mult>
<Op Mult> ::= <Op Mult> '*' <Op Unary>
| <Op Mult> '/' <Op Unary>
| <Op Mult> '%' <Op Unary>
| <Op Unary>
<Op Unary> ::= '!' <Op Unary>
| '~' <Op Unary>
| '-' <Op Unary>
| '*' <Op Unary>
| '&' <Op Unary>
| '++' <Op Unary>
| '--' <Op Unary>
| <Op Pointer> '++'
| <Op Pointer> '--'
| '(' <Native Type> <Pointer Mod> ')' <Op Unary> !
CAST
| sizeof '(' <Type> ')'
| <Op Pointer>
<Op Pointer> ::= <Op Pointer> '.' <Value>
| <Op Pointer> '->' <Value>
| <Op Pointer> '[' <Expr> ']'
| <Value>
<Value> ::= <Literal Value>
| <Func Call>
| Id
| '(' <Expr> ')'
<Literal Value> ::= <Numeric Literal>
| StringLiteral
| CharLiteral
<Numeric Literal> ::= <Integer Literal>
| FloatLiteral
<Integer Literal> ::= OctLiteral
| DecLiteral
| HexLiteral
! [End of
Grammar]----------------------------------------------------------------------------------