[antlr-interest] declarations after code

Maassen, H.A.M. H.A.M.Maassen at student.tue.nl
Tue Nov 23 02:02:40 PST 2004


Thinking about this, would it be possible to jump the lexer and parser around the code to skip the statements until the declarations section is parsed and then go back and parse them?
 
Code
  a b c
 
Type
  a = func
  b = func
  c = func
 
So my parser would look something like this:
 
program: {store position 1} 
         (.)* declarations 
         {store position 2} 
         {go to position 1} 
         statements 
         {go to position2};
statements: "code" (var)*;
declarations "type" ( var EQUALS type )*;
 
Can something like this be done?
 
Or what if I buffer the tokens read in the statements block?
 
program: { buffering=true; } 
         statements 
         { buffering=false;} 
         declarations 
         { parse buffered statements; };
statements: "code" (var)*;
declarations "type" ( var EQUALS type )*;
 
Any thoughts would be greatly appreciated :)
Regards, Harald Maassen

	-----Original Message----- 
	From: Maassen, H.A.M. 
	Sent: Tue 11/23/2004 10:27 AM 
	To: antlr-interest at yahoogroups.com 
	Cc: 
	Subject: [antlr-interest] declarations after code
	
	

	Hello,
	
	I'm in a bit of a fix :)
	
	I'm currently writing a parser for a language that can have variables declared after the code where they are used. In addition, the language is ambiguous depending on the types of the variables.
	
	For example, the following code results in two different trees depending on the types of the variables "a", "b" and "c":
	
	Code
	  a b c
	
	Here, "a" could be a function that takes "b" and "c" as parameters or "a", "b" and "c" could each be separate functions (the language has no statement-separator).
	
	It looks like I'll have to do two passes over the code, once to get all the variable types and once to parse the statements (and then a treewalk for full blown semantic checks).
	
	Can anyone think of a cleaner solution to this problem?
	
	Je vous prie d'agréer, madame, monsieur, l'expression de mes sentiments distingués,
	Harald Maassen
	
	
	
	Yahoo! Groups Links
	
	
	
	
	



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
    antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/ms-tnef
Size: 7006 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20041123/5aacc820/attachment.bin


More information about the antlr-interest mailing list