Click here to Skip to main content
14,448,369 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: we need to harness this talent for CodeProject ! Pin
PIEBALDconsult2-Jan-20 19:20
professionalPIEBALDconsult2-Jan-20 19:20 
GeneralRe: we need to harness this talent for CodeProject ! Pin
BillWoodruff3-Jan-20 2:12
mveBillWoodruff3-Jan-20 2:12 
GeneralRe: we need to harness this talent for CodeProject ! Pin
Mark_Wallace3-Jan-20 0:50
MemberMark_Wallace3-Jan-20 0:50 
GeneralMy observations on parser generators Pin
honey the codewitch2-Jan-20 15:07
mvahoney the codewitch2-Jan-20 15:07 
GeneralRe: My observations on parser generators Pin
Greg Utas2-Jan-20 16:04
professionalGreg Utas2-Jan-20 16:04 
GeneralRe: My observations on parser generators Pin
honey the codewitch2-Jan-20 16:10
mvahoney the codewitch2-Jan-20 16:10 
GeneralRe: My observations on parser generators Pin
Greg Utas2-Jan-20 16:59
professionalGreg Utas2-Jan-20 16:59 
GeneralRe: My observations on parser generators Pin
honey the codewitch2-Jan-20 17:13
mvahoney the codewitch2-Jan-20 17:13 
The man pages are actually VERY good. But also Using <CODE>flex</CODE> - An Overview of @code{flex}, with Examples[^]

That's a very basic tutorial on using flex.

Download Flex[^]

Now, here's something for some reason nobody really talks about.

In practice, forget those samples. They give you basics but nothing real world. Real world though, is even easier.

Have a set of constants for all your symbols. If you intend to parse >= you need a GREATERTHANOREQUAL/GTE constant. Give it an int value. Do it for all your terminals. It doesn't matter what the values are. You're going to use these to distinguish your tokens.

In your scanner:

%option unicode, codepage:raw, out: outputfile.c


%{
// extra code.
%}

%%
<<EOF>>		{ return EOS; }

"int" {return INT_TYPE; }
"uint" { return UINT_TYPE; }
// all keywords BEFORE IDENT
(_|[[:IsLetter:]])(_|[[:IsLetterOrDigit:]])* { return IDENT; }


// ignore whitespace
[\r\n\t\v\f ] 

// capture anything we didn't get upstream and report it as an error
[\n]|[^\n] { return ERROR; }


basically you just return a constant a value for every token you capture. You can do more - whatever code you need in those brackets is fine. I use them for building my skip lists inside those little brace breakouts above where we return consts. Like
{ yyskip(LINE_COMMENT); }
since i didn't return a value, flex simply "hides" it. It only gives you something back when you return. otherwise it just keeps going. yyskip() is a function I made that would have been included in the "extra code" part above. It adds the current value to my skiplist.

Oh to get access to these values you use int symid = yylex();
and the text returned is in yytext

It's all pretty simple. It's a bit of work defining your tokens and consts up front but hey, it's a lot less work than parsing them yourself.

And it will make this FAST.


I actually generate these files using Parsley Laugh | :laugh:
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.

GeneralRe: My observations on parser generators Pin
honey the codewitch2-Jan-20 16:54
mvahoney the codewitch2-Jan-20 16:54 
GeneralRe: My observations on parser generators Pin
Mark_Wallace3-Jan-20 0:55
MemberMark_Wallace3-Jan-20 0:55 
GeneralVisual Studio and WINE? Pin
honey the codewitch2-Jan-20 13:00
mvahoney the codewitch2-Jan-20 13:00 
GeneralRe: Visual Studio and WINE? Pin
Kornfeld Eliyahu Peter2-Jan-20 13:07
mveKornfeld Eliyahu Peter2-Jan-20 13:07 
GeneralRe: Visual Studio and WINE? Pin
Eddy Vluggen2-Jan-20 13:55
professionalEddy Vluggen2-Jan-20 13:55 
GeneralRe: Visual Studio and WINE? Pin
honey the codewitch2-Jan-20 13:59
mvahoney the codewitch2-Jan-20 13:59 
GeneralRe: Visual Studio and WINE? Pin
Eddy Vluggen2-Jan-20 14:38
professionalEddy Vluggen2-Jan-20 14:38 
GeneralRe: Visual Studio and WINE? Pin
theoldfool2-Jan-20 14:51
professionaltheoldfool2-Jan-20 14:51 
GeneralRe: Visual Studio and WINE? Pin
honey the codewitch2-Jan-20 14:56
mvahoney the codewitch2-Jan-20 14:56 
GeneralRe: Visual Studio and WINE? Pin
Eddy Vluggen3-Jan-20 3:40
professionalEddy Vluggen3-Jan-20 3:40 
GeneralRe: Visual Studio and WINE? Pin
honey the codewitch3-Jan-20 5:04
mvahoney the codewitch3-Jan-20 5:04 
GeneralRe: Visual Studio and WINE? Pin
dandy723-Jan-20 4:44
Memberdandy723-Jan-20 4:44 
GeneralRe: Visual Studio and WINE? Pin
honey the codewitch3-Jan-20 5:02
mvahoney the codewitch3-Jan-20 5:02 
GeneralRe: Visual Studio and WINE? Pin
#realJSOP2-Jan-20 15:24
mva#realJSOP2-Jan-20 15:24 
GeneralRe: Visual Studio and WINE? Pin
Mark_Wallace3-Jan-20 0:57
MemberMark_Wallace3-Jan-20 0:57 
GeneralRe: Visual Studio and WINE? Pin
lopatir2-Jan-20 16:57
Memberlopatir2-Jan-20 16:57 
GeneralRe: Visual Studio and WINE? Pin
honey the codewitch2-Jan-20 17:00
mvahoney the codewitch2-Jan-20 17:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.