Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Lexing/parsing advice sought(Noob)
Lexing/parsing advice sought [message #1143248] Fri, 18 October 2013 04:36 Go to next message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
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: Sat, 19 October 2013 01:54]

Report message to a moderator

Re: Lexing/parsing advice sought [message #1143328 is a reply to message #1143248] Fri, 18 October 2013 05:44 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 13488
Registered: July 2009
Senior Member
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?


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: Lexing/parsing advice sought [message #1143857 is a reply to message #1143328] Fri, 18 October 2013 13:25 Go to previous messageGo to next message
Gary Worsham is currently offline Gary WorshamFriend
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 Go to previous messageGo to next message
Uli Merkel is currently offline Uli MerkelFriend
Messages: 248
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

Re: Lexing/parsing advice sought [message #1145378 is a reply to message #1144971] Sat, 19 October 2013 13:16 Go to previous message
Gary Worsham is currently offline Gary WorshamFriend
Messages: 176
Registered: September 2013
Senior Member
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: Mon Jul 06 06:32:26 GMT 2020

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

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

Back to the top