Visit the LQ Articles and Editorials section
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-10-2007, 11:47 AM   #1
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,

Old 03-10-2007, 08:25 PM   #2
Senior Member
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,487

Rep: Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627Reputation: 627
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?



Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

All times are GMT -5. The time now is 01:39 PM.

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