473,503 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: ply yacc lineno not working?

I'm sorry for the dumb question. I had to add these to the lexer:

def t_comment(t):
r"\#[^\n]*\n"
t.lexer.lineno += 1
# We do not return anything - comments are ignored.

# Define a rule so we can track line numbers
def t_newline(t):
r'\n+'
t.lexer.lineno += len(t.value)
Well, it is not very straightforward. From the docs, it was not clear
that I HAVE TO increment t.lexer.lineno in my lexer if you want yacc to
parse line numbers. But it is logical. I believe this could be done
automatically, since "line number" ALWAYS means "\n", there is nothing
to be configured here. (Am I wrong? There can be parsers to parse files
where new lines are chr(255) or something?)

Thanks,

Laszlo

Jun 27 '08 #1
1 2000
I dunno but on Dos/Windows a newline is usually \r\n (although that still
includes a \n..)

"Laszlo Nagy" <ga*****@shopzeus.comwrote in message
news:ma***************************************@pyt hon.org...
I'm sorry for the dumb question. I had to add these to the lexer:

def t_comment(t):
r"\#[^\n]*\n"
t.lexer.lineno += 1
# We do not return anything - comments are ignored.

# Define a rule so we can track line numbers
def t_newline(t):
r'\n+'
t.lexer.lineno += len(t.value)
Well, it is not very straightforward. From the docs, it was not clear that
I HAVE TO increment t.lexer.lineno in my lexer if you want yacc to parse
line numbers. But it is logical. I believe this could be done
automatically, since "line number" ALWAYS means "\n", there is nothing to
be configured here. (Am I wrong? There can be parsers to parse files where
new lines are chr(255) or something?)

Thanks,

Laszlo

Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

18
10713
by: Moonlit | last post by:
Hi, I am searching for the best lex and yacc combination (or something similar) that can be used in combination with C++ and that can contain C++ code. I have the regular flex/bison port working...
4
6327
by: Profetas | last post by:
Hi. I was wondering how can I access the yacc functions? because when use a normal yacc function such as qstring { yylval.string = strdup(yytext+1); if(yylval.string !='"')...
1
2599
by: Jarek | last post by:
Hello! I'm trying to fix code of esnacc to compile it in gcc4.0. I've fixed almost all c/c++ code, but I've completly no idea about yacc. Can someone help me how to fix the following warnings: ...
13
4989
by: Berk Birand | last post by:
Hi, I am working on a school project where we use lex/yacc to write a compiler for a fictional (Java-like) language. I have handled all the details about the yacc and lex files, but I still have...
2
7488
by: max.giacometti | last post by:
Hi everybody! I am using lex and yacc to write a vhdl to systemc converter. Lex simply reads the input file and yacc implements grammar and translation. I'd like to be able to make yacc...
2
4002
by: Wolfgang Draxinger | last post by:
I'm currently working on a laguange similair in concept to Vala (google for it on the Gnome project site). A (very) high level language is translated into intermediary C, which is then compiled to...
0
1155
by: Laszlo Nagy | last post by:
This is a fragment from my yacc file: import ply.yacc as yacc from lex import tokens from ast import * def p_msd(p): r"""msd : SCHEMA WORD LBRACE defs RBRACE """ p = MSDSchema(p)
1
2009
by: Robert | last post by:
If the goal is to take a 1-dimensional package of text and produce a tree data structure that is easy to understand and manipulate, and then write C/C++ code that works with that tree - does...
1
5165
by: mh | last post by:
I'm porting a C lex/yacc based project, and would like to redo it in python. What's the best option for a python lex/yacc-like? I've googled a few things, but wanted to see the current...
0
7072
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.