help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Whether to Parser


From: Hans Åberg
Subject: Re: Whether to Parser
Date: Sat, 13 May 2017 18:17:01 +0200

> On 13 May 2017, at 14:54, Prashant Shah <address@hidden> wrote:

> I am using bison with flex (I am quite new with parsers).
> 
> I want to parse a grammar as given below:
> 
> char a = 'A'
> int i = 5555
> float f = 23.456
> 
> What is the best way to represent the grammar ?
> 
> 1) declaration : datatype IDENTIFIER '=' CONSTANT;
> 
> datatype : CHAR
>                | INT
>                | FLOAT
> 
> 
> 2) declaration : CHAR IDENTIFIER '=' CHAR_CONST
>                        | INT IDENTIFIER '=' INT_CONST
>                        | FLOAT IDENTIFIER '=' FLOAT_CONST
> 
> In the (1) option above where do I parse what type of "CONSTANT" it is ?
> 
> The (2) option seems to be very verbose.

You need both: When the parser sees 2), it puts the identifier name on a lookup 
table along with its type. When the lexer sees an identifier, it checks whether 
it is on the lookup table, and if it is, returns its reference on the table and 
the grammar variable for use in 1), otherwise just an identifier to be defined 
for use in 2).





reply via email to

[Prev in Thread] Current Thread [Next in Thread]