lex

Is it possible to set priorities for rules to avoid the “longest-earliest” matching pattern?

有些话、适合烂在心里 提交于 2019-12-03 10:30:27
Another simple question : is there any way to tell flex to prefer a rule that matches a short thing over a rule that matches a longer thing ? I can't find any good documentation about that. Here is why I need that : I parse a file for a pseudo language that contains some keywords corresponding to control instructions. I'd like them to be the absolute priority so that they're not parsed as parts of an expression. I actually need this priority thing because I don't have to write a full grammar for my project (that would be totally overkill in my case since I perform structural analysis on the

Flex, continuous scanning stream (from socket). Did I miss something using yywrap()?

♀尐吖头ヾ 提交于 2019-12-03 08:48:30
Working on a socketbased scanner (continuous stream) using Flex for pattern recognition. Flex doesn't find a match that overlaps 'array bounderies'. So I implemented yywrap() to setup new array content as soon yylex() detects <> (it will call yywrap). No success so far. Basically (for pin-pointing my problem) this is my code: %{ #include <stdio.h> #include <string.h> #include <stdlib.h> #define BUFFERSIZE 26 /* 0123456789012345678901234 */ char cbuf1[BUFFERSIZE] = "Hello everybody, lex is su"; // Warning, no '\0' char cbuf2[BUFFERSIZE] = "per cool. Thanks! "; char recvBuffer[BUFFERSIZE]; int

Is there a better (more modern) tool than lex/flex for generating a tokenizer for C++?

三世轮回 提交于 2019-12-03 04:42:46
问题 I recent added source file parsing to an existing tool that generated output files from complex command line arguments. The command line arguments got to be so complex that we started allowing them to be supplied as a file that was parsed as if it was a very large command line, but the syntax was still awkward. So I added the ability to parse a source file using a more reasonable syntax. I used flex 2.5.4 for windows to generate the tokenizer for this custom source file format, and it worked.

How to make lex/flex recognize tokens not separated by whitespace?

匿名 (未验证) 提交于 2019-12-03 03:03:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm taking a course in compiler construction, and my current assignment is to write the lexer for the language we're implementing. I can't figure out how to satisfy the requirement that the lexer must recognize concatenated tokens. That is, tokens not separated by whitespace. E.g.: the string 39if is supposed to be recognized as the number 39 and the keyword if . Simultaneously, the lexer must also exit(1) when it encounters invalid input. A simplified version of the code I have: %{ #include <stdio.h> %} %option main warn debug %% if | then

Amazon Lex not prompting for missing variables when using CodeHook Validation

匿名 (未验证) 提交于 2019-12-03 02:38:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am building an agent in Amazon Lex with around 3 intents. All the 3 intents have a variable which has been ticked as 'required', meaning the agent has to prompt for those variables when the user query is missing it. However when I am using a lambda function as codehook validation the , function gets triggered without prompting for the missing variable. For example: Intent which describes call notes from a call with a specific person: The prompt is " Specify the name of the person whose notes you want to see' The objective of the lambda

What is the difference between Flex/Lex and Yacc/Bison?

我与影子孤独终老i 提交于 2019-12-03 00:37:22
问题 What is the difference between Flex & Lex and Yacc & Bison. I searched the Internet wildly and I didn't find any solid answer. Can I install pure Lex and Yacc on Ubuntu, or I can install only flex and bison. I am confused. Is Lex or Yacc still being maintained by someone? Are all of them free? If Lex is not free why do I have it installed on my Ubuntu distribution? lex --version lex 2.5.35 回答1: There are some differences between Lex and Flex, but you have to be abusing Lex to run into the

Is there a better (more modern) tool than lex/flex for generating a tokenizer for C++?

断了今生、忘了曾经 提交于 2019-12-02 17:12:23
I recent added source file parsing to an existing tool that generated output files from complex command line arguments. The command line arguments got to be so complex that we started allowing them to be supplied as a file that was parsed as if it was a very large command line, but the syntax was still awkward. So I added the ability to parse a source file using a more reasonable syntax. I used flex 2.5.4 for windows to generate the tokenizer for this custom source file format, and it worked. But I hated the code. global variables, wierd naming convention, and the c++ code it generated was

how to resolve 2+2 and 2++2 conflict

不羁岁月 提交于 2019-12-02 14:51:13
问题 In larger program I have given the following (flex/bison) In flex: pn [\+|\-] dig [0-9]+ exp [e|E]{dig}+ . . . "+" {printf("+ detected\n"); return PLUS_SIGN;} {pn}?{dig}+ { printf("digit detected - %s\n",yytext); sscanf(yytext, "%d", (int*)&yylval); return TYPE_INT;} In Bison: expr: expr PLUS_SIGN expr { $$ = $1 + $3; printf(" $$=%f\n",$$); } | TYPE_INT { $$ = (int)$1; printf(" $$=%f\n",$$); } ; The problem is: When I give 2+2 it recognizes 2 and +2 instead of 2 , + , 2 How can I get it to do

Calling flex from a makefile

旧时模样 提交于 2019-12-02 12:50:15
I would like to call flex to build a .l file, then call gcc to build everything. I tryed: comp: lex scanner.l \ gcc -o a.out main.c hash.c -I. error: lex scanner.l \ gcc -o a.out main.c hash.c -I. lex: impossible to opne gcc /usr/bin/m4:stdin:2994: ERROR: end of file in string and lex scanner.l <tab> gcc -o a.out main.c hash.c -I. error: missing separator. The lex.yy.c generate by lex has is being included in the main file. Thanks in advance, Pedro all: a.out lex.yy.c: scanner.l lex scanner.l a.out: lex.yy.c main.c hash.c gcc -o a.out main.c hash.c -I. Try this: lex.yy.c: scanner.l lex scanner

Ignoring errors in yacc/lex

梦想与她 提交于 2019-12-02 09:04:04
I'm new to yacc/lex and I'm working on a parser that was written by someone else. I notice that when an undefined token is found, the parser returns an error and stops. Is there a simple way to just make it ignore completely lines that it cannot parse and just move on to the next one? just add a rule that looks like . { // do nothing } at the bottom of all of your rules, and it will just ignore everything it comes across that doesn't fit any of the previous rules. Edit: if you have multiple states, then a catch-all that works in any state would then look like: <*>. { } 来源: https:/