flex-lexer

[af]?lex regular expression difference

陌路散爱 提交于 2019-12-12 06:39:41
问题 I don't know how to do this, and I've found no good resources online for how to perform this operation[.] I'm trying to take an annotated EBNF production rule which is a difference between two regular expressions and turn it into a(n a| f?)lex grammar specification rule[.] The problem is that I see no way to do this normally[.]{3} is there a way to do this using Kleene algebra, like the way you can use an empty match with alternation in a context-free grammar[?] 回答1: What does the EBNF

Best way to add generated files to distribution?

若如初见. 提交于 2019-12-12 05:30:58
问题 I have a quite complex (C++) project using autoconf / automake, which includes some "generated" files (foo.yy -> foo.cc). Actual builds are done using a "control script" (Gentoo .ebuild for those familiar with the concept), on various platforms. Now, one of the target platforms does not properly support the foo.yy -> foo.cc step, and has to use the foo.cc file generated on a Linux box. Now I have two ways to go about this: 1) Check in foo.cc into the project repository and somehow patch

Meaning of “<*>” in lex

只愿长相守 提交于 2019-12-12 05:23:15
问题 I know,we can define some conditions in lex, matching: 1.<DIRECTIVE>{STRING} {printf("Matching the DIRECTIVE state!");} 2.<REFERENCE>{INTEGER} {printf("Matching the REFERNCE state!");} 3.[\n] {printf("Matching the INITIAL state?");} 4.<*>{DOBULE} {printf("Matching all state include INITIAL? Seem not!");} How to use the states in the right way? What is the difference in conditions on line 3 and 4? The whole .l file, cut by me,now it just to realize a reference.When I run it,it can work well

lex parser not displaying hex correctly

℡╲_俬逩灬. 提交于 2019-12-12 03:39:56
问题 I'm trying to identify a hex number from a parsed text file and everything is about 99% accurate however I keep having an issue with this certain instance 0xa98h. whenever it finds this line it will output 0xa98 instead of ignoring it altogether since it is not valid. I've tried so many variations to this code and have yet to find a way to exclude that issue. [-]?[0][x|X][0-9A-F]+ {cout << yytext << " Number" << endl; } 回答1: The pattern for hex numbers does not consider digits 'a' ... 'f'.

How to define a boolean in Flex

…衆ロ難τιáo~ 提交于 2019-12-12 03:36:39
问题 I am building a compiler for a toy Java language (Decaf) and I am having trouble with defining a bool. When I try to analyze a boolean, it always returns false, whether or not I wrote false. Flex code: true|false { yylval.boolConstant = yytext; return T_BoolConstant; } Input code: bool x = true; bool y = false; Output: true T_BoolConstant (value = false) false T_BoolConstant (value = false) I tried searching on SO but this was the closest I could get to a proper answer: Simulating Booleans in

How to detect partial unfinished token and join its pieces that are obtained from two consequent portions of input?

可紊 提交于 2019-12-12 03:36:38
问题 I am writing toy terminal, where I use Flex to parse normal text and control sequences that I get from tty. One detail of Cocoa machinery is that it reads from tty by chunks of 1024 bytes so that any token described in my .lex file at any time can become broken into two parts: some bytes of a token are the last bytes of first 1024 chunk and remaining bytes are the very first bytes of next 1024 bytes chunk. So I need to somehow: First of all detect this situation: when a token is split between

Optimizing flex string literal parsing

孤街浪徒 提交于 2019-12-12 03:34:03
问题 I am starting writing a lexical analyzer for my programming language. String literals in this language start with a " and end when an unescaped " is encountered. Everything inside (including newlines) is preserved, except escape sequences (the usual \n s, \t s, \" s etc plus a way of escaping a character by using its ASCII code, e.g. \097 or \97 ). This is the code I have written so far: %{ #include <iostream> #define YY_DECL extern "C" int yylex() std::string buffstr; %} %x SSTATE %% \" {

How to get such pattern matching of regular expression in lex

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 03:08:12
问题 Hi I want to check a specific pattern in regular expression but I'm failed to do that. Input should be like noun wordname : wordmeaning I'm successful getting noun and wordname but couldn't design a pattern for word meaning. My code is : int state; char *meaning; char *wordd; ^verb { state=VERB; } ^adj { state = ADJ; } ^adv { state = ADV; } ^noun { state = NOUN; } ^prep { state = PREP; } ^pron { state = PRON; } ^conj { state = CONJ; } //my try but failed [:\a-z] { meaning=yytext; printf("

Unrecognized rule in lex on Ubuntu 14.04

风格不统一 提交于 2019-12-12 02:05:34
问题 I am attempting to have lex use echo to spit back out reserved words in a program but I continue to get the following errors: scanner.l:30: unrecognized rule scanner.l:30: unrecognized rule scanner.l:70: unrecognized rule scanner.l:70: unrecognized rule scanner.l:70: unrecognized rule scanner.l:71: unrecognized rule scanner.l:71: unrecognized rule Below is my scanner code for lex: %{ #include <stdio.h> #include <ctype.h> #include "tokens.h" %} ws [ \t\r\n]+ quoted \".*\" letter [A-Za-z] digit

BISON : no shift/reduce conflicts

╄→гoц情女王★ 提交于 2019-12-12 01:37:08
问题 I wrote this code to create a pascal parser . When the bison analyse it, it doesn't show any conflict despite it's a left recursive and ambigous grammar. this is the code %{ #include<stdio.h> int yyparse(); int yylex(); int yyerror(char *s); %} %token ID; %token VAR; %token INT; %token FUNC; %token PROC; %token BEGIN; %token END; %token OPAFFECT; %token OPREL; %token OPADD; %token OPMUL; %token PROGRAM; %token NB; %token IF; %token THEN; %token ELSE; %token WHILE; %token DO; %token NOT;