Symbol tables and type checking [closed] - parsing

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have two orthogonal questions related to symbol tables:
Should I build the symbol table and perform type checking as I parse the code? Parsing first and then traversing the AST to build the symbol table looks cleaner to me. However, I like the idea of having an immutable AST (similar to Clang), and I can't have that in a two-step process (as I would need to insert extra type conversion nodes in the type checking phase).
Should the symbol table be responsible for doing type checking? I read multiple articles in which symbol tables are used for this purpose. Is that a recommended practice? It looks rather awkward to me.
Note: I am using a top-down recursive descent parser.

I believe this is what you should do:
First one: You should build your AST first, then, as you said traverse it to fill the symbol table up and do the type-checking. The immutable AST seems good, but it won't be as clean traversing the AST.
Second one: Yes, symbol tables should have a part in type-checking (not do type-checking). It will be needed to store the types of things like variables. There is nothing awkward about it :-)

Related

How to generate the same random sequence from a given seed in Delphi [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
I am wanting to generate the same random sequence (of numbers or characters) based on a given "seed" value.
Using the standard Randomize function does not seem to have such an option.
For example in C# you can initialize the Random function with a seed value (Random seed c#).
How can I achieve something similar in Delphi?
You only need to assign a particular value to the RandSeed global variable.
Actually, I'm almost surprised you asked, because you clearly know of the Randomize function, the documentation for which states the following:
The random number generator should be initialized by making a call to Randomize, or by assigning a value to RandSeed.
The question did not mention thread safety as a requirement, but the OP specified that in comments.
In general, pseudorandom number generators have internal state, in order to calculate the next number. So they cannot be assumed to be thread-safe, and require an instance per thread.
For encapsulated thread-safe random numbers, one alternative is to use a suitably good hash function, such as xxHash, and pass it a seed and a counter that you increment after each call in the thread.
There is a Delphi implementation of xxHash here:
https://github.com/Xor-el/xxHashPascal
For general use, it's easy to make several versions in 1, 2 or 3 dimensions as needed, and return either floating point in 0..1 or integers in a range.

This program is a combination of stacks queue and linked list [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I do not know how to solve this question and I have a deadline for this assignment can you please help me solving it:
The car names are saved in a linked list. The customer orders are saved in the queue. You should take order from the beginning of the queue and search for it in the linked list, then delete it and put the sold car in the stack to be able to retrieve the last sold car.
The program must be written in C language
As you didn't share your attempt (your code) in your post, here I am sharing the pseudocode for this problem. You should write your own code to solve your assignment.
ProcessOrder(LinkedList<CarDetails> ll, Queue<Order> Q, Stack<Order> S):
while(!Q.empty()):
Order currentOrder = Q.top()
Q.pop()
CarDetails cd = findAndDeleteFromLinkList(ll, currentOrder.car_name)
S.push(CarDetails)
Now to write the code by your own, you can use the following resources:
How to use the STL stack in C++
Stack Implementation in C
How to Use C++ STL Queue with an Example Program
How To Implement Queue in C?
C function to find and delete a node from a singly linked list

What is the rule for multiple methods(?) on and object (i.e. num.to_s.chars.map{|x| x.to_i**2}.join.to_i)? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
What is the structural rule of something like this? I'm newer to programming and I don't know the technical term for the ".something's" (methods?).
But, in this example, there are 5 (to_s, chars, map, join, and to_i).
num.to_s.chars.map{|x| x.to_i**2}.join.to_i
Basically, all I am wondering is, what is the structure to building these? I've tried doing some similar and have received errors. So, is there a specific order or structure to these? And is the correct term method?
Ideally you should first get fundamental of ruby language. Ruby is one of the easiest language to get hold on. Checkout https://try.ruby-lang.org and you will better understand following.
It's an expression where there is chain of methods being called on the result of each expression.
Assuming num is an integer, see the comment below
num
.to_s # to_s on any ruby object converts it to string
.chars # returns individual characters in string array
.map { |x| # iterates over each number character in array
x.to_i**2 # and convert each character to integer and sqare it( ** is exponent operator)
}
.join # map returns new array and join/conctenate each number
.to_i # convert it back to integer
so if num is 123, it returns 149 which essentially each number is squared.
You can try yourself by running this code one by one in irb

is one hot encoding is free of the dummy trap [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
there is a thing called dummy trap in one hot encoder that is when we encode the categorical column with 3 categories lest say a,b,and c then with one hot encoder we get 3 categories like or columns a, b ,and c but when we use get_dummies we get 2 columns instead a, and b then it is save from dummy trap. is one hot encoding exposed to dummy trap or it takes care of it . am i right? which one is save of dummy trap? or is it ok to use both with our removing columns, iam using the dataset for many algorithms.
looking for help . thanks in advance.
OneHotEncoder cannot process string values directly. If your nominal features are strings, then you need to first map them into integers.
pandas.get_dummies is kind of the opposite. By default, it only converts string columns into one-hot representation, unless columns are specified.

Design advice for file parser [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am trying to design an edifact parser, I was planning on having one class to read the file, one class to map the data and then one other class to deal with data storage. The part where I am having a major problem is in how instances of those classes should communicate with each other. Any advice would be appreciated.
I don't see a need for the classes to communicate (pass messages) but would suggest some Strategy pattern be used.
You'll have a class to read the file and make sense of it's Syntax. For example, something which can handle whitespace and return formatted information like 'token', 'word' etc.
The class which reads and parses syntax is passed into the Semantic parser. The Semantic parser makes sense of the meaning. For example you might expect "Id, command, token, string" in that order. The Semantic parser might use a Command pattern.
The Semantic class outputs structured data, so is passed into your structure builder (builder pattern).
So your code might look like;
MyDataStructure = DataBuilder(SemanticParser(SyntaxParse(FileReader(filename))));
HTH

Resources