English 中文(简体)
1. 编制简编
原标题:Programming a simple compiler

我是一位简单语言的汇编者。

我做了一种弹性/象征性的制片,在<代码>stdout上填写了标语。

现在,我想作一些理论分析,但我不知道如何修改我的灵活性,以便把标语作为投入。

  • A linked list is extremely inefficient for large files (source files around 80MB take about 1.3GB of ram)
  • I could modify my lexer to give the next token every time it is called (idea taken from the Dragon Book), but I don t know what I will do if somewhere in the process I have to go back and read a previous token.

做这些事情的正确途径是什么?

问题回答

Implementing a nextToken() method in the lexical analyser is the standard way. This method is called by the parser (or syntax analyser) until the entire input has been consumed.

but I dont what I will do if somewhere in the process i have to go back and read a previous token

This is not usually the case. But, what the parser may need to do is push back a token (or a number of tokens depending on the lookahead of the parser) which has already been seen. In this case the lexer provides a pushBack(Token) which ensures that the next call to nextToken() will return the supplied token, rather than the next token appearing in the input.

但是,如果在该进程的某些地方必须回头看一去,我会做些什么。

It sounds like your matches are too greedy.

You might look into Backtracking





相关问题
Split Strings and arrange db to display products in PHP

I m new in php. Could you please help me to find the way to properly arrange following task: Table "Products" id - details 1 - 1-30,2-134:6:0;;2-7:55:0;;1-2,2-8:25:0 - where this string can be ...

Lucene Query WITHOUT Operators

I am trying to use Lucene to search for names in a database. However, some of the names contain words like "NOT" and "OR" and even "-" minus symbols. I still want the different tokens inside the names ...

Google-like search query tokenization & string splitting

I m looking to tokenize a search query similar to how Google does it. For instance, if I have the following search query: the quick "brown fox" jumps over the "lazy dog" I would like to have a ...

Recursive woes - reducing an input string

I m working on a portion of code that is essentially trying to reduce a list of strings down to a single string recursively. I have an internal database built up of matching string arrays of varying ...

Tokenize from a textfile reading into an array in C

How do you tokenize when you read from a file in C? textfile: PES 2009;Konami;DVD 3;500.25; 6 Assasins Creed;Ubisoft;DVD;598.25; 3 Inferno;EA;DVD 2;650.25; 7 char *tokenPtr; fileT = fopen("DATA2....

tokenize a string keeping delimiters in Python

Is there any equivalent to str.split in Python that also returns the delimiters? I need to preserve the whitespace layout for my output after processing some of the tokens. Example: >>> s="...

C tokenize polynomial coefficients

I m trying to put the coefficients of polynomials from a char array into an int array I have this: char string[] = "-4x^0 + x^1 + 4x^3 - 3x^4"; and can tokenize it by the space into -4x^0 x^1 4x^3 ...

Approaching Text Parsing in Scala

I m making an application that will parse commands in Scala. An example of a command would be: todo get milk for friday So the plan is to have a pretty smart parser break the line apart and ...

热门标签