C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 24th, 2013, 04:05 AM
jmgr jmgr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 jmgr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 13 sec
Reputation Power: 0
Flex/Bison details and error handling.

Hi,
I have inherited an assembler in Flex/Bison, and it all compiles and works, and I can make simple changes to the build.

However, the error handling is less than ideal, and I have found a truly strange action in the flex coded conditional handling.

I can find the source lines for IFDEF/ELSE/ENDIF, and nothing leaps out, but I am no .l expert.

Take the example, of what lexer.l swallows aka std asm.:

ASM Code:
Original - ASM Code
  1. ;TestTrue EQU 1
  2. LLif    EQU  30H   ; FAILS in some contexts only
  3. LLi_f    EQU  30H   ; OK                 
  4.      MOV     R1,LLif   ; fine outside IFDEFs 
  5. IFDEF TestTrue  ; something fishy here - parser triggers on EMBEDDED if - inside another word  ?!                 
  6.      MOV     R1,LLi_f  ; this one fails if spelt LLif   
  7. ELSE                 
  8.     MOV     R1,LLif   ; this one is OK
  9. ENDIF


The Trigger conditions are the word if (which is a valid operator) must be inside a conditional block, and actually inside the non-active area, and only in that 'zone' does it change its neurons, and sees any if at all, even one contained inside a longer word, as being another conditional level.

Remove the spelling of if and it all work 100%, add back the LLif , (or Life, or Fifo ) and it fails, and rather ungracefully.

I've tried different versions of Flex/Bison, and they seem to make no difference.

So the issue must be something in the lexer.l, but what can do something as basic as flip to consider sub-strings, only in some areas ?

I can see blocks called
<COND_SKIP> and <COND_SCAN> which seem to manage the Conditionals, but nothing that says 'when inside a non-active conditional block, change keyword rules from whole word, to substring' - besides, this behaviour is not something anyone would code deliberately, it has to be an accident

Does anyone know how to .l code specifies whole words, or substring matches ?

Or, does anyone know of an example assembler, or just a IFDEF style conditional processor, in lexer.l format ?
If I can find simple example code that does not do this, I can try spot the difference.

I know it triggers the conditional parser, as if I write this {nonsense}, it Assembles with no errors ?!
ASM Code:
Original - ASM Code
  1.  
  2. ;TestTrue EQU 1
  3. LLif    EQU  30H   ; FAILS in some contexts only
  4. LLi_f    EQU  30H   ; OK
  5.                 MOV     R1,LLif   ; fine outside IFDEFs
  6.  
  7.   IFDEF TestTrue  ; something fishy here - parser triggers on EMBEDDED if ?!
  8.                 MOV     R1,LLif  ; this one fails if spelt LLif
  9.                              ENDIF ; nonsense line matches phantom if -> works 100%
  10.   ELSE
  11.                 MOV     R1,LLif   ; this one is OK
  12.   ENDIF 

Reply With Quote
  #2  
Old January 24th, 2013, 10:50 AM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,358 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 38 m 34 sec
Reputation Power: 383
I suggest you post the flex and bison files. From there we can ask further relevant questions.
__________________
[code]Code tags[/code] are essential for python code!

Reply With Quote
  #3  
Old January 24th, 2013, 02:53 PM
jmgr jmgr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 jmgr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 13 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
I suggest you post the flex and bison files. From there we can ask further relevant questions.


Thanks, I think I have narrowed it down to these chunks below.

If I have this right then this line

<ASM>IFNB { BEGIN BLANK; return IFNB; }

applied the rules in <ASM> until it finds "IFNB" then returns - but is that return via a call to label IFNB, or just text "IFNB"
- I can only find IFNB within a block called
<COND_SCAN>, where it seems to be 'text match' not a label ?
(see below)
Or are text matches in quotes only, and anything else is a public label ?


My guess is the first rule branch is OK, but then the rules applied while looking for the matching COND, are too lax, and do not require whole words ?

- but I also would have expected the basic 'whole words' stuff to be common across most tests ?


FLEX Code:
Original - FLEX Code
    <COND_SCAN>{ [ \t\r]+        ; /* ignore  whitespace */ \;.*            ;   /* ignore comments */ "//".*      ; /* ignore comments */ #IF  { condp = push_cond(condp, S_IGNORE, T_CPRE); } #IFDEF    { condp = push_cond(condp, S_IGNORE, T_CPRE); } #IFNDEF  { condp = push_cond(condp, S_IGNORE, T_CPRE); } \.IF        { condp = push_cond(condp, S_IGNORE, T_DOT); } IF    { condp = push_cond(condp, S_IGNORE, T_MCS); } IFB  { condp = push_cond(condp, S_IGNORE, T_MCS); } IFN  { condp = push_cond(condp, S_IGNORE, T_MCS); } IFNB        { condp = push_cond(condp, S_IGNORE, T_MCS); } IFDEF      { condp = push_cond(condp, S_IGNORE, T_MCS); } IFNDEF    { condp = push_cond(condp, S_IGNORE, T_MCS); } #ELIF      { if ((condp == NULL) || (condp->type != T_CPRE)) {             do_err("No matching #IF", yylloc, 43, 1);           }           else if (condp->state == S_FALSE) {             yylineno--; yyless(0);             BEGIN ASM;           }         } /* etc */


and also these 'starter' paths

Flex Code:
Original - Flex Code
    /* plenty of these */ <ASM>IFN    { return IFN; } <ASM>IFNB   { BEGIN BLANK; return IFNB; } <ASM>IFDEF  { return IFDEF; } /* Which I think apply this ? */ <ASM>{ \'[^'\n]*\' { if (yytext[yyleng-1] != '\'') {             do_err("String not terminated", yylloc, 33, 1);           } else if (yytext[yyleng-2] == '\\') {             yyless(yyleng-1);             yymore();           } else {             if (yyleng == 3) {               yylval.value = yytext[1];               return NUMBER;             } else if (yyleng == 4) {               yylval.value = (yytext[1] <<8) | yytext[2];               return NUMBER;             } else {               yylval.str = do_ascii(yytext, '\''); //strdup(yytext);               return STRING;             }           }         }

Reply With Quote
  #4  
Old January 24th, 2013, 03:25 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,358 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 38 m 34 sec
Reputation Power: 383
Gosh I see many return statements in the flex source. To where might this function return?

Reply With Quote
  #5  
Old January 24th, 2013, 10:39 PM
jmgr jmgr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 3 jmgr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 36 m 13 sec
Reputation Power: 0
Quote:
Originally Posted by b49P23TIvg
Gosh I see many return statements in the flex source. To where might this function return?


If I understand Flex right, they return to a after the
BEGIN ASM;
- however the coarse, flow of the sw is fine, I am looking for something subtle, as to how a skipping block, flips from whole-word tests to within-word finds... ?

Reply With Quote
  #6  
Old January 24th, 2013, 10:46 PM
b49P23TIvg's Avatar
b49P23TIvg b49P23TIvg is online now
Contributing User
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Aug 2011
Posts: 3,358 b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level)b49P23TIvg User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 3 Days 9 h 38 m 34 sec
Reputation Power: 383
The return statements return tokens to the bison parser. For complex error handling you need to understand the interaction between the parser and lexical analyzer.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Flex/Bison details and error handling.

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap