Lexing/parsing advice sought [message #1143248] |
Fri, 18 October 2013 04:36 |
Gary Worsham Messages: 176 Registered: September 2013 |
Senior Member |
|
|
I am making OK progress with my DSL.
[Edit: the original question has been solved, it was pilot error and so there is no point in having people read it! Deleting the original question in favor of my current questions. Thanks to Christian for his response; now you know why it makes no sense any more].
My new question is:
Can anyone tell me why my "SC_COMMENT" rule
terminal SC_COMMENT : ';' !('\n'|'\r')* ('\r'? '\n')?;
seems to work OK until there is an instruction.
; first comment
; second comment
rdax tempo, 1.5
rda delay+100, 1.3
; third comment
An error comes up at the third comment:
extraneous input '; third comment\r\n' expecting EOF
If I comment out that comment with //, then the rest of the instructions are parsed OK (the ones after the third comment).
Also, what's the easiest way to make the rules case-insensitive? For example, I want to treat RDAX and rdax as the same thing. Other variations are less important. The reason this is important is that there is a fairly large body of existing code that could be either way.
What am I doing wrong?
Thanks,
GW
[Updated on: Sat, 19 October 2013 01:54] Report message to a moderator
|
|
|
|
Re: Lexing/parsing advice sought [message #1143857 is a reply to message #1143328] |
Fri, 18 October 2013 13:25 |
Gary Worsham Messages: 176 Registered: September 2013 |
Senior Member |
|
|
[Edit: Sorry, pilot error, the code under test was using a different instruction that is still assigned the old rule. I still have a question about my SC_COMMENT rule though!]
OK, here's my full grammar.
grammar com.holycityaudio.spincad.SpinCAD with org.eclipse.xtext.common.Terminals
generate spinCAD "http://www.holycityaudio.com/spincad/SpinCAD"
Program:
equates += Equate*
mem += Mem*
comments += Comment*
instructions += Instruction*
;
// {Instruction}
//-----------------------------------------------------------------------------
Equate:
EquDouble | EquInt | EquEyeD;
EquDouble:
'equ' ename = ID value = SPINREAL
;
EquInt:
'equ' ename = ID value = INT
;
EquEyeD:
'equ' ename = ID value = ID
;
Comment:
cname = SC_COMMENT
;
Mem:
'mem' buffer = ID length = INT
;
Instruction:
Inst_B15_S1_9 |
Inst_B6_S1_14 |
Inst_S1_14_S1_10 |
Inst_B6 |
Inst_B24 |
Inst |
Skip |
Jam
;
Inst_B6_S1_14:
ReadRegister |
WriteRegister |
ReadRegisterFilter |
Maxx |
WriteRegisterHighPass |
WriteRegisterLowPass
;
Inst_B15_S1_9:
ReadDelay |
WriteDelay |
WriteAllPass
;
Inst_B6:
Mulx |
Ldax
;
Inst_B24:
And |
Or |
Xor
;
Inst:
Clr | Not | Absa
;
Inst_S1_14_S1_10:
Exp | ScaleOffset
;
ReadRegister: 'rdax' arg1 = ID ',' arg2 = SPINREAL;
WriteRegisterLowPass: 'wrlx' arg1 = ID ',' arg2 = SPINREAL;
WriteRegisterHighPass: 'wrhx' arg1 = ID ',' arg2 = SPINREAL;
WriteRegister: 'wrax' arg1 = ID ',' arg2 = SPINREAL;
Maxx: 'maxx' arg1 = ID ',' arg2 = SPINREAL;
ReadRegisterFilter: 'rdfx' arg1 = ID ',' arg2 = SPINREAL;
Mulx: 'mulx' arg1 = ID;
Ldax: 'ldax' arg1 = ID;
Exp: 'exp' arg1 = SPINREAL ',' arg2 = SPINREAL;
ScaleOffset: 'sof' arg1 = SPINREAL ',' arg2 = SPINREAL;
WriteDelay: 'wra' arg1 = ID ('^' | '#' | ('+' arg3 = INT))? ',' arg2 = SPINREAL;
WriteAllPass: 'wrap' arg1 = ID ('^' | '#' | ('+' arg3 = INT))? ',' arg2 = SPINREAL;
ReadDelay: 'rda' arg1 = ID ('^' | '#' | ('+' arg3 = INT))? ',' arg2 = SPINREAL;
And: 'and' arg1 = INT;
Or: 'or' arg1 = INT;
Xor: 'xor' arg1 = INT;
Clr: 'clr';
Not: 'not';
Absa: 'absa';
Skip: 'skp' arg1 = ID ',' arg2 = ID;
Jam: 'jam' arg1=ID;
//------------------------
terminal SPINREAL : ('0'..'1') '.' ('0'..'9')*;
terminal SC_COMMENT : ';' !('\n'|'\r')* ('\r'? '\n')?;
//terminal LABEL : ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
// terminal MEMADDR : ('a'..'z'|'A'..'Z'|'_')('a'..'z'|'A'..'Z'|'_'|'0'..'9')* ('+' INT)?;
Many thanks!
GW
[Updated on: Sat, 19 October 2013 01:53] Report message to a moderator
|
|
|
Re: Lexing/parsing advice sought [message #1144971 is a reply to message #1143857] |
Sat, 19 October 2013 06:50 |
Uli Merkel Messages: 250 Registered: June 2013 |
Senior Member |
|
|
Hi Gary,
your grammar has a fixed sequence for program:
all equates at first,
then all men
then all comments
then all instructions.
Because of this, you are not allowed to place a comment after an instruction line.
Have a look in the XTEXT documentation for "abstract element" to get a flexible sequence. I'ts all a matter of the pipe "|", what you already use to allow flexibility for your instructions.
[Updated on: Sat, 19 October 2013 06:52] Report message to a moderator
|
|
|
|
Powered by
FUDForum. Page generated in 0.03012 seconds