ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Perhaps I should have included some text with this link. I am trying to create a language, which this one is called PNFHA (Portable Numbers Format High Level Language A). It is not working. It doesn't like the ID or ID = expression after a print or var command. The syntax seems to describe it okay, but it doesn't work in practice. The link is where I origionally posted it, but to get faster responses, I posted it here too. It seems that this site is the one I'm getting responses on for these sets of problems for this language, so that's good, but I wasn't sure where I would get responses. If you'd rather, I could've copied the question into here.
I was thinking that enabling debugging for bison when I looked at it might be a good idea. But I am having trouble enabling debugging. Here is my changed file:
It won't let me post the code, so I'll just explain what I did for my hack. I inserted statements to always print to standard error, everywhere it conditionally prints to it. I said the same thing it wanted to say.
Now I get an output of:
Code:
Starting parse
Entering state 0
Entering state 1
Reading a token: Entering state 8
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 7
Entering state 21
Reading a token: Entering state 20
Entering state 19
Entering state 33
Entering state 15
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 7
Entering state 21
Reading a token: Entering state 35
Reading a token: Entering state 7
Entering state 48
Reading a token: Entering state 21
Entering state 20
Entering state 19
Entering state 33
Entering state 15
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 7
Entering state 21
Reading a token: * ERROR: scan error
Entering state 20
Entering state 19
* ERROR: syntax error, unexpected NUMBER, expecting SEND or COMMA
Entering state 3
Entering state 13
Entering state 1
Entering state 7
Entering state 21
Reading a token: Entering state 20
Entering state 19
Entering state 33
Entering state 15
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 9
Entering state 22
Entering state 20
Entering state 19
Reading a token: Entering state 33
Entering state 15
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 5
Reading a token: Entering state 7
Entering state 28
Reading a token: Entering state 38
Reading a token: Entering state 7
Entering state 51
Reading a token: Entering state 28
Entering state 43
Entering state 21
Reading a token: Entering state 20
Entering state 19
Entering state 33
Entering state 15
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 6
Reading a token: Entering state 8
Entering state 29
Reading a token: Entering state 30
Entering state 45
Entering state 18
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 6
Reading a token: Entering state 8
Entering state 29
Reading a token: Entering state 8
Entering state 44
Entering state 30
Reading a token: Entering state 45
Entering state 18
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 9
Entering state 22
Entering state 20
Entering state 19
Reading a token: Entering state 33
Entering state 15
Entering state 14
Entering state 13
Entering state 1
Reading a token: Entering state 9
Entering state 22
Entering state 20
Entering state 19
Reading a token: Entering state 33
Entering state 15
Entering state 14
Entering state 13
Entering state 1
Reading a token: Now at end of input.
Entering state 2
What does this mean the error is? How do I fix it?
I found out I enabled debugging fine, and I was calling flex wrong, telling it to output, "phfha.cpp", instead of "pnfha.cpp". This enabled debugging. Now the output is as follows, with an unmodified parser/lexer:
Code:
Entering state 5
Reading a token: Next token is token NUMBER ()
Shifting token NUMBER ()
Entering state 7
Reducing stack by rule 21 (line 130):
$1 = token NUMBER ()
-> $$ = nterm number_expression ()
Stack now 0 1 5
Entering state 28
Reading a token: Next token is token OPTIMES ()
Shifting token OPTIMES ()
Entering state 38
Reading a token: Next token is token NUMBER ()
Shifting token NUMBER ()
Entering state 7
Reducing stack by rule 21 (line 130):
$1 = token NUMBER ()
-> $$ = nterm number_expression ()
Stack now 0 1 5 28 38
Entering state 51
Reading a token: Next token is token RIGHTP ()
Reducing stack by rule 24 (line 133):
$1 = nterm number_expression ()
$2 = token OPTIMES ()
$3 = nterm number_expression ()
-> $$ = nterm number_expression ()
Stack now 0 1 5
Entering state 28
Next token is token RIGHTP ()
Shifting token RIGHTP ()
Entering state 43
Reducing stack by rule 29 (line 138):
$1 = token LEFTP ()
$2 = nterm number_expression ()
$3 = token RIGHTP ()
-> $$ = nterm number_expression ()
Stack now 0 1
Entering state 21
Reading a token: Next token is token SEND ()
Reducing stack by rule 19 (line 125):
$1 = nterm number_expression ()
-> $$ = nterm exp ()
Stack now 0 1
Entering state 20
Reducing stack by rule 17 (line 121):
$1 = nterm exp ()
-> $$ = nterm expression ()
Stack now 0 1
Entering state 19
Next token is token SEND ()
Shifting token SEND ()
Entering state 33
Reducing stack by rule 11 (line 105):
$1 = nterm expression ()
$2 = token SEND ()
-> $$ = nterm expression_statement ()
Stack now 0 1
Entering state 15
Reducing stack by rule 7 (line 99):
$1 = nterm expression_statement ()
-> $$ = nterm statement ()
Stack now 0 1
Entering state 14
Reducing stack by rule 4 (line 94):
$1 = nterm statement ()
-> $$ = nterm line ()
Stack now 0 1
Entering state 13
Reducing stack by rule 2 (line 90):
$1 = nterm input ()
$2 = nterm line ()
-> $$ = nterm input ()
Stack now 0
Entering state 1
Reading a token: Next token is token LEFTB ()
Shifting token LEFTB ()
Entering state 6
Reading a token: Next token is token SEND ()
Shifting token SEND ()
Entering state 8
Reducing stack by rule 6 (line 98):
$1 = token SEND ()
-> $$ = nterm statement ()
Stack now 0 1 6
Entering state 29
Reading a token: Next token is token RIGHTB ()
Reducing stack by rule 15 (line 117):
$1 = nterm statement ()
-> $$ = nterm temp_statement_block ()
Stack now 0 1 6
Entering state 30
Next token is token RIGHTB ()
Shifting token RIGHTB ()
Entering state 45
Reducing stack by rule 14 (line 114):
$1 = token LEFTB ()
$2 = nterm temp_statement_block ()
$3 = token RIGHTB ()
-> $$ = nterm statement_block ()
Stack now 0 1
Entering state 18
Reducing stack by rule 10 (line 102):
$1 = nterm statement_block ()
-> $$ = nterm statement ()
Stack now 0 1
Entering state 14
Reducing stack by rule 4 (line 94):
$1 = nterm statement ()
-> $$ = nterm line ()
Stack now 0 1
Entering state 13
Reducing stack by rule 2 (line 90):
$1 = nterm input ()
$2 = nterm line ()
-> $$ = nterm input ()
Stack now 0
Entering state 1
Reading a token: Next token is token LEFTB ()
Shifting token LEFTB ()
Entering state 6
Reading a token: Next token is token SEND ()
Shifting token SEND ()
Entering state 8
Reducing stack by rule 6 (line 98):
$1 = token SEND ()
-> $$ = nterm statement ()
Stack now 0 1 6
Entering state 29
Reading a token: Next token is token SEND ()
Shifting token SEND ()
Entering state 8
Reducing stack by rule 6 (line 98):
$1 = token SEND ()
-> $$ = nterm statement ()
Stack now 0 1 6 29
Entering state 44
Reducing stack by rule 16 (line 118):
$1 = nterm statement ()
$2 = nterm statement ()
-> $$ = nterm temp_statement_block ()
Stack now 0 1 6
Entering state 30
Reading a token: Next token is token RIGHTB ()
Shifting token RIGHTB ()
Entering state 45
Reducing stack by rule 14 (line 114):
$1 = token LEFTB ()
$2 = nterm temp_statement_block ()
$3 = token RIGHTB ()
-> $$ = nterm statement_block ()
Stack now 0 1
Entering state 18
Reducing stack by rule 10 (line 102):
$1 = nterm statement_block ()
-> $$ = nterm statement ()
Stack now 0 1
Entering state 14
Reducing stack by rule 4 (line 94):
$1 = nterm statement ()
-> $$ = nterm line ()
Stack now 0 1
Entering state 13
Reducing stack by rule 2 (line 90):
$1 = nterm input ()
$2 = nterm line ()
-> $$ = nterm input ()
Stack now 0
Entering state 1
Reading a token: Next token is token ID ()
Shifting token ID ()
Entering state 9
Reducing stack by rule 30 (line 141):
$1 = token ID ()
-> $$ = nterm variable_expression ()
Stack now 0 1
Entering state 22
Reducing stack by rule 20 (line 126):
$1 = nterm variable_expression ()
-> $$ = nterm exp ()
Stack now 0 1
Entering state 20
Reducing stack by rule 17 (line 121):
$1 = nterm exp ()
-> $$ = nterm expression ()
Stack now 0 1
Entering state 19
Reading a token: Next token is token SEND ()
Shifting token SEND ()
Entering state 33
Reducing stack by rule 11 (line 105):
$1 = nterm expression ()
$2 = token SEND ()
-> $$ = nterm expression_statement ()
Stack now 0 1
Entering state 15
Reducing stack by rule 7 (line 99):
$1 = nterm expression_statement ()
-> $$ = nterm statement ()
Stack now 0 1
Entering state 14
Reducing stack by rule 4 (line 94):
$1 = nterm statement ()
-> $$ = nterm line ()
Stack now 0 1
Entering state 13
Reducing stack by rule 2 (line 90):
$1 = nterm input ()
$2 = nterm line ()
-> $$ = nterm input ()
Stack now 0
Entering state 1
Reading a token: Next token is token ID ()
Shifting token ID ()
Entering state 9
Reducing stack by rule 30 (line 141):
$1 = token ID ()
-> $$ = nterm variable_expression ()
Stack now 0 1
Entering state 22
Reducing stack by rule 20 (line 126):
$1 = nterm variable_expression ()
-> $$ = nterm exp ()
Stack now 0 1
Entering state 20
Reducing stack by rule 17 (line 121):
$1 = nterm exp ()
-> $$ = nterm expression ()
Stack now 0 1
Entering state 19
Reading a token: * ERROR: scan error
* ERROR: scan error
Next token is token ID ()
* ERROR: syntax error, unexpected ID, expecting SEND or COMMA
Error: popping nterm expression ()
Stack now 0 1
Shifting token error ()
Entering state 3
Reducing stack by rule 5 (line 95):
$1 = token error ()
-> $$ = nterm line ()
Stack now 0 1
Entering state 13
Reducing stack by rule 2 (line 90):
$1 = nterm input ()
$2 = nterm line ()
-> $$ = nterm input ()
Stack now 0
Entering state 1
Next token is token ID ()
Shifting token ID ()
Entering state 9
Reducing stack by rule 30 (line 141):
$1 = token ID ()
-> $$ = nterm variable_expression ()
Stack now 0 1
Entering state 22
Reducing stack by rule 20 (line 126):
$1 = nterm variable_expression ()
-> $$ = nterm exp ()
Stack now 0 1
Entering state 20
Reducing stack by rule 17 (line 121):
$1 = nterm exp ()
-> $$ = nterm expression ()
Stack now 0 1
Entering state 19
Reading a token: * ERROR: scan error
Next token is token SEND ()
Shifting token SEND ()
Entering state 33
Reducing stack by rule 11 (line 105):
$1 = nterm expression ()
$2 = token SEND ()
-> $$ = nterm expression_statement ()
Stack now 0 1
Entering state 15
Reducing stack by rule 7 (line 99):
$1 = nterm expression_statement ()
-> $$ = nterm statement ()
Stack now 0 1
Entering state 14
Reducing stack by rule 4 (line 94):
$1 = nterm statement ()
-> $$ = nterm line ()
Stack now 0 1
Entering state 13
Reducing stack by rule 2 (line 90):
$1 = nterm input ()
$2 = nterm line ()
-> $$ = nterm input ()
Stack now 0
Entering state 1
Reading a token: Now at end of input.
Shifting token $end ()
Entering state 2
Stack now 0 1 2
Cleanup: popping token $end ()
Cleanup: popping nterm input ()
This is at least a lot clearer. Lets see if I can tell what it means...
The, "a", before it's declared is actually an error, but I haven't gotten that far yet. After it's been declared however, it cannot be used or it generates an error, "* ERROR: 7: syntax error, unexpected ID, expecting SEND". How do I fix this?
I'll repeat what I posted in your other thread: you're posting far too much code. You have to go through it yourself to work out what the problem is and then post just enough to reproduce it. I doubt anyone will read through such a large amount of code, attempt to understand it and debug it for you.
I've gotten further. To see my current progress, please look at: http://www.linuxquestions.org/questi...43#post5206243. I posted another thread because this one was getting too old and too complicated to go on, so I'm marking this one solved, but am on this next step. There has been too many changes to continue with this thread...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.