[antlr-interest] [C target] how to skip empty lines

Юрушкин Михаил yurushkin at rambler.ru
Thu Oct 22 22:17:01 PDT 2009


  писал(а) в своём письме Fri, 23 Oct 2009 08:46:24 +0400:

> Kevin J. Cummings <cummings at kjchome.homeip.net> писал(а) в своём письме  
> Fri, 23 Oct 2009 04:15:18 +0400:
>
>> On 10/22/2009 06:08 PM, Юрушкин Михаил wrote:
>>> Good evening.
>>> thanks for your support!
>>>
>>> Could u give me one tip.
>>> I user C target and want to parse such input
>>>
>>> "a = 3.14
>>> f(x) = 3x^2 - 4x + 2
>>>
>>> print "The value of f for " a " is " f(a)
>>> print "The derivative of " f() " is " f'()
>>>
>>>
>>> list variables
>>> list functions
>>>
>>> g(y) = 2y^3 + 6y - 5
>>> h = f + g
>>> print h()"
>>>
>>> I use this tutorial
>>> http://jnb.ociweb.com/jnb/jnbJun2008.html
>>>
>>> but parser fails.. when finds empty lines. It's correct, but how can i  
>>> fix
>>> it? It's common problem for all languages. Programmer can input some  
>>> empty
>>> lines between constructions to improve code readability...
>>
>> Have your "whitespace" be "skipped" by your lexer?  That's what I do in
>> almost every compiler I've written.  Your lexer tokenizes, and tokens
>> can be seperated by whitespace, so, so long as you don't have lexer
>> rules where whitespace is significant, you should be OK.

mmm.. I understand this. Thank u. But I a little another problem FOR  
RORTRAN GRAMMAR

first example: stmnt <\n> stmnt <\n> stmnt <;> <\n> // i mean <\n> is  
enough to seperate statements.
<\n> token shouldn't be skiped -it's used by end_of_statement rule.

But it's possible to write
stmnt <\n> <\n> <\n> <stmnt> <\n>
in this case 2nd and 3rd <\n> tokens do not figure in any rules.. they  
must be skiped.

So hmm... it's a problem for lexer. what whould u advice to do with  
grammars?
I know one method but it needs to write code to "override nextToken  
method" - but i think it's not good decision.

Thank u very much!

-- 
Best regards,
Michael


More information about the antlr-interest mailing list