Re: Context sensitive scanner ? (Quinn Tyler Jackson)
7 Dec 1997 22:12:55 -0500

          From comp.compilers

Related articles
[9 earlier articles]
Re: Context sensitive scanner ? (Albert Theo Hofkamp) (1997-11-29)
Re: Context sensitive scanner ? (Scott Stanchfield) (1997-11-30)
Re: Context sensitive scanner ? (1997-11-30)
Re: Context sensitive scanner ? (Scott Stanchfield) (1997-11-30)
Re: Context sensitive scanner ? (Chris Clark USG) (1997-12-05)
Re: Context sensitive scanner ? (Mark Thiehatten) (1997-12-07)
Re: Context sensitive scanner ? (1997-12-07)
| List of all articles for this month |

From: (Quinn Tyler Jackson)
Newsgroups: comp.compilers
Date: 7 Dec 1997 22:12:55 -0500
Organization: Parse City
References: 97-11-117
Keywords: parse



This simple Visual Parse++ grammar demonstrates a reply
to the following question, posted in comp.compilers by

>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:



{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

ArrayDescriptor, 'x.', %push InArray;

Integer, 'INT';

Real, 'REAL';

%expression InArray

'.' %ignore, %pop;
'{ws}' %ignore, %pop;

'{dot}' ArraySubscriptOperator, 'ARRAY_DOT';

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;


Quinn Tyler Jackson -- "The Artful Parser"


Post a followup to this message

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