Related articles |
---|
[9 earlier articles] |
Re: Context sensitive scanner ? hat@se-46.wpa.wtb.tue.nl (Albert Theo Hofkamp) (1997-11-29) |
Re: Context sensitive scanner ? thetick@magelang.com (Scott Stanchfield) (1997-11-30) |
Re: Context sensitive scanner ? johnm@non.net (1997-11-30) |
Re: Context sensitive scanner ? thetick@magelang.com (Scott Stanchfield) (1997-11-30) |
Re: Context sensitive scanner ? clark@quarry.zk3.dec.com (Chris Clark USG) (1997-12-05) |
Re: Context sensitive scanner ? mark@research.techforce.nl (Mark Thiehatten) (1997-12-07) |
Re: Context sensitive scanner ? qjackson@direct.ca (1997-12-07) |
From: | qjackson@direct.ca (Quinn Tyler Jackson) |
Newsgroups: | comp.compilers |
Date: | 7 Dec 1997 22:12:55 -0500 |
Organization: | Parse City |
References: | 97-11-117 |
Keywords: | parse |
// GRAMMAR BEGINS
/*
This simple Visual Parse++ grammar demonstrates a reply
to the following question, posted in comp.compilers by
a.hofkamp@wtb.tue.nl:
>We are busy writing a language where the following
>constructs occur:
> 1) Literal reals (such as 1.2),
> 2) Nested index operations on arrays (such as x.1.2).
[...]
> Since the scanner is not context-sensitive, it
> does not understand that the second expression
> should be returned as IDEN x, DOT, NUM 1, DOT NUM 2
> I am aware of the capability of creating states in
> Lex, but I do not really like it, since it heavily
> depends on the exact moment of executing
> when YACC statements (at the end of a rule).
The parse tree generated by the following data stream:
x.1.2 1.2
can be seen at:
http://mypage.direct.ca/q/qjackson/x12parse_tree.gif
*/
%macro
{dot} '\.';
{id} '[a-zA-Z_][a-zA-Z0-9_]*';
{ws} '[ \t\n]+';
{digit} '[0-9]';
%expression main
'.' %ignore; // for this demo we ignore this
'{ws}' %ignore; // for this demo we ignore this
'{id}{dot}'
ArrayDescriptor, 'x.', %push InArray;
'{digit}+'
Integer, 'INT';
'{digit}+{dot}{digit}*'
Real, 'REAL';
%expression InArray
'.' %ignore, %pop;
'{ws}' %ignore, %pop;
'{dot}' ArraySubscriptOperator, 'ARRAY_DOT';
'{digit}+'
Index, 'INDEX';
%production S
Lambda lambda -> ;
S_00 S -> lambda;
S_01 S -> particle S;
ParticleReal particle -> real;
ParticleArray particle -> array;
RealNumber real -> 'REAL';
Array array -> 'x.' index;
IndexSimple index -> 'INDEX';
IndexCompound index -> 'INDEX' 'ARRAY_DOT' index;
// GRAMMAR ENDS
--
Quinn Tyler Jackson -- "The Artful Parser"
email: qjackson@direct.ca
url: http://mypage.direct.ca/q/qjackson/
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.