Skip to main content



      Home
Home » Modeling » TMF (Xtext) » Lexing/parsing advice sought(Noob)
Lexing/parsing advice sought [message #1143248] Fri, 18 October 2013 00:36 Go to next message
Eclipse UserFriend
I am making OK progress with my DSL. Very Happy

[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: Fri, 18 October 2013 21:54] by Moderator

Re: Lexing/parsing advice sought [message #1143328 is a reply to message #1143248] Fri, 18 October 2013 01:44 Go to previous messageGo to next message
Eclipse UserFriend
i i cannot reproduce that using

Model:
	s+=WriteDelay*;
	
WriteDelay: 'wra' arg1 = ID ('+' arg3=INT)? ',' arg2 = SPINREAL;

SPINREAL: INT ("." INT);

can you post a complete reproducable grammar?
Re: Lexing/parsing advice sought [message #1143857 is a reply to message #1143328] Fri, 18 October 2013 09:25 Go to previous messageGo to next message
Eclipse UserFriend
[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: Fri, 18 October 2013 21:53] by Moderator

Re: Lexing/parsing advice sought [message #1144971 is a reply to message #1143857] Sat, 19 October 2013 02:50 Go to previous messageGo to next message
Eclipse UserFriend
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 02:52] by Moderator

Re: Lexing/parsing advice sought [message #1145378 is a reply to message #1144971] Sat, 19 October 2013 09:16 Go to previous message
Eclipse UserFriend
Hi Uli,

Thanks so much for the clue! I was trying to reinvent terminal rules and getting really confused. With everyone's help, I am now really close to accomplishing the first major step of my goal! Very Happy Very Happy Very Happy Very Happy

GW
Previous Topic:ClusteringBuilderState - Error validating
Next Topic:[Xtext] scope provider migration - DI issue?
Goto Forum:
  


Current Time: Wed Jul 23 14:22:25 EDT 2025

Powered by FUDForum. Page generated in 0.06519 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top