LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-10-2007, 11:47 AM   #1
unreal07
LQ Newbie
 
Registered: Mar 2007
Posts: 1

Rep: Reputation: 0
Using Flex and Bison to parse the variable declaration section in Pascal


Hi everyone, I'm undertaking a project to convert Pascal to ARM assembler using Flex and Bison with C++. I have a problem when attempting to add variable information to a symbol table. The problem is as follows:

In Pascal, when a variable is declared, the TYPE of the variable follows the actual identifier e.g.

VAR a,b : int;

When my parser interprets this line, it cannot tell that "a" and "b" are integers until it reaches the end of the line. So, when adding to my symbol table, I must use some sort of temporary store to save a list of identifiers encountered before the end of the line, at which point I finally know the TYPE of variable, and it can be added to the symbol table.

The grammar I am using is as follows:

D -> L : T (Variable declaration)
T -> identifier (The TYPE i.e. integer, char or user defined type)
L -> L , identifier | identifier (list of variables)

I was wondering if there is a better method of solving this problem, for example changing the underlying grammar rules, rather than implementing an extra data structure to temporarily store the variable names.

Thanks in advance,

M
 
Old 03-10-2007, 08:25 PM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
It is looooooooong time ago that I remotely understood wat YACC (Bison now) did. But I am sure that there are YACC scripts available for the Pascal language. Why not start from there?

jlinkels
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Do flex and bison support C++? ankit4u1 Programming 7 08-08-2011 04:56 PM
installing bison and flex rameshsena Linux - Software 10 06-21-2010 11:33 AM
LXer: Handle Your Errors Using Flex and Bison LXer Syndicated Linux News 0 08-02-2006 09:33 AM
bison / flex zaman Programming 1 08-16-2005 10:19 AM
bison, flex and make problem ChimpFace9000 Programming 4 05-19-2002 07:49 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:53 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration