[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SV: Language with multiple statements on one line
Seems like I can answer my own question.. :-) I figured it out.. (maybe someone else want to know it also)
Fixed grammar:
Helpers
letter = ['A'..'Z'] | ['a'..'z'];
digit = ['0'..'9'];
cr = 13;
lf = 10;
tab = 9;
not_cr_lf = [tab + [[32..127] - [cr + lf]]];
nl = lf | cr | cr lf;
colon = ':';
space = ' ';
underscore = '_';
Tokens
assign = '=';
identifier = letter (letter | digit)*;
number = digit+;
separator = colon;
new_line = nl;
blank = (tab | space)*;
Ignored Tokens
blank;
Productions
lines =
{program} statements new_line lines |
{line} statements new_line;
statements =
{list} statement separator statements |
{single} statement |
{empty};
statement =
{assignment} identifier assign expression;
expression =
{value} value;
value =
{constant} number |
{identifier} identifier;
-----Opprinnelig melding-----
Fra: owner-sablecc-list@sable.mcgill.ca
[mailto:owner-sablecc-list@sable.mcgill.ca]På vegne av Jørgensen Paul
Rene (Networks)
Sendt: 7. januar 2004 13:31
Til: sablecc-list@sable.mcgill.ca
Emne: Language with multiple statements on one line
Hi,
I'm trying to write a language grammar that supports multiple statements on one line separated by a colon (like good old Basic).
Example program
### BEGIN
<nl>
A=4 : B=5<nl>
<nl>
<nl>
A=A+B<nl>
<nl>
B=1 : C=1<nl>
<nl>
### END
I can't make this to work... I want full flexibility to insert as many nl's as I want anywhere in between, at the top and so on. (I've inserted <nl>'s to indicate a line feed.
Please help..
This is my current grammar that try to use:
Package org.learn;
Helpers
letter = ['A'..'Z'] | ['a'..'z'];
digit = ['0'..'9'];
cr = 13;
lf = 10;
tab = 9;
not_cr_lf = [tab + [[32..127] - [cr + lf]]];
nl = lf | cr | cr lf;
colon = ':';
space = ' ';
Tokens
assign = '=';
identifier = letter (letter | digit)*;
number = digit+;
separator = (nl+ | colon);
blank = (tab | space)*;
Ignored Tokens
blank;
Productions
statements =
{list} statement statements |
{empty} ;
statement =
{assignment} identifier assign expression separator;
expression =
{value} value;
value =
{constant} number |
{identifier} identifier;