lexical-analysis

What are the tools for semantic analysis phase of compiler construction?

喜欢而已 提交于 2020-02-27 09:21:49
问题 Compiler construction can be divided into several phases such as Lexical analysis, Syntax analysis, Semantic analysis and etc. In lexical analysis, there are tools such as Lex, Flex and etc. In syntax analysis, there are tools such as Yacc, Bison, etc. I'm just curious what are the tools available for semantic analysis phase? 回答1: To the best of my knowledge there are no language-agnostic tools to perform type checking and if there were, they'd certainly not be generally applicable as many

Parsing Python function calls to get argument positions

和自甴很熟 提交于 2020-01-22 20:15:34
问题 I want code that can analyze a function call like this: whatever(foo, baz(), 'puppet', 24+2, meow=3, *meowargs, **meowargs) And return the positions of each and every argument, in this case foo , baz() , 'puppet' , 24+2 , meow=3 , *meowargs , **meowargs . I tried using the _ast module, and it seems to be just the thing for the job, but unfortunately there were problems. For example, in an argument like baz() which is a function call itself, I couldn't find a simple way to get its length. (And

How do I list out all English terms in a sentence that indicate an animal?

好久不见. 提交于 2020-01-04 03:16:08
问题 For example, in the sentence " The two horses had just lain down when a brood of ducklings, which had lost their mother, filed into the barn, cheeping feebly and wandering from side to side to find some place where they would not be trodden on. ", there are two animals: horse and duck. I was looking for vocabulary lists for animal names but was unable to get anything that's complete enough. The WordNet database looks promising but may be overkill and not broad enough either. 回答1: WordNet is

How can lexing efficiency be improved?

旧城冷巷雨未停 提交于 2020-01-01 11:25:24
问题 In parsing a large 3 gigabyte file with DCG, efficiency is of importance. The current version of my lexer is using mostly the or predicate ;/2 but I read that indexing can help. Indexing is a technique used to quickly select candidate clauses of a predicate for a specific goal. In most Prolog systems, indexing is done (only) on the first argument of the head. If this argument is instantiated to an atom, integer, float or compound term with functor, hashing is used to quickly select all

Writing a Z80 assembler - lexing ASM and building a parse tree using composition?

徘徊边缘 提交于 2020-01-01 04:45:11
问题 I'm very new to the concept of writing an assembler and even after reading a great deal of material, I'm still having difficulties wrapping my head around a couple of concepts. What is the process to actually break up a source file into tokens? I believe this process is called lexing, and I've searched high and low for a real code examples that make sense, but I can't find a thing so simple code examples very welcome ;) When parsing, does information ever need to be passed up or down the tree

DFA based regular expression matching - how to get all matches?

别来无恙 提交于 2019-12-31 17:25:57
问题 I have a given DFA that represent a regular expression. I want to match the DFA against an input stream and get all possible matches back, not only the leastmost-longest match. For example: regex: a*ba|baa input: aaaaabaaababbabbbaa result: aaaaaba aaba ba baa 回答1: Assumptions Based on your question and later comments you want a general method for splitting a sentence into non-overlapping, matching substrings, with non-matching parts of the sentence discarded. You also seem to want optimal

DFA based regular expression matching - how to get all matches?

你说的曾经没有我的故事 提交于 2019-12-31 17:25:11
问题 I have a given DFA that represent a regular expression. I want to match the DFA against an input stream and get all possible matches back, not only the leastmost-longest match. For example: regex: a*ba|baa input: aaaaabaaababbabbbaa result: aaaaaba aaba ba baa 回答1: Assumptions Based on your question and later comments you want a general method for splitting a sentence into non-overlapping, matching substrings, with non-matching parts of the sentence discarded. You also seem to want optimal

Profiler/Analyzer for Erlang?

别等时光非礼了梦想. 提交于 2019-12-30 07:57:48
问题 Are there any good code profilers/analyzers for Erlang? I need something that can build a Call graph for my code. 回答1: For static code analysis you have XREF and DIALYZER, for profiling you can use cprof, fprof or eprof, you can get good reference here... 回答2: The 'fprof' module includes profiling features. From the fprof module documentation: fprof:apply(foo, create_file_slow, [junk, 1024]). fprof:profile(). fprof:analyse(). fprof:apply (or trace ) runs the function, profile converts the

Profiler/Analyzer for Erlang?

牧云@^-^@ 提交于 2019-12-30 07:57:10
问题 Are there any good code profilers/analyzers for Erlang? I need something that can build a Call graph for my code. 回答1: For static code analysis you have XREF and DIALYZER, for profiling you can use cprof, fprof or eprof, you can get good reference here... 回答2: The 'fprof' module includes profiling features. From the fprof module documentation: fprof:apply(foo, create_file_slow, [junk, 1024]). fprof:profile(). fprof:analyse(). fprof:apply (or trace ) runs the function, profile converts the

How do i implement If statement in Flex/bison

拥有回忆 提交于 2019-12-29 11:41:54
问题 I dont get the error, please can you help me out, here is the .l and .y file.thanks. %{ #include "ifanw.tab.h" extern int yylval; %} %% "=" { return EQ; } "!=" { return NE; } "<" { return LT; } "<=" { return LE; } ">" { return GT; } ">=" { return GE; } "+" { return PLUS; } "-" { return MINUS; } "*" { return MULT; } "/" { return DIVIDE; } ")" { return RPAREN; } "(" { return LPAREN; } ":=" { return ASSIGN; } ";" { return SEMICOLON; } "IF" { return IF; } "THEN" { return THEN; } "ELSE" { return