[DEV] change heritage order of lexer
This commit is contained in:
parent
5c49f39c2e
commit
440ec14e6f
@ -14,6 +14,156 @@
|
|||||||
#include <eci/File.h>
|
#include <eci/File.h>
|
||||||
|
|
||||||
namespace eci {
|
namespace eci {
|
||||||
|
namespace interpreter {
|
||||||
|
enum type {
|
||||||
|
typeBlock, //!< block area definition
|
||||||
|
typeType, //!< type definition
|
||||||
|
typeVariable, //!< new variable use
|
||||||
|
typeVariableDeclaration, //!< new variable definition
|
||||||
|
typeFunction, //!< function definition
|
||||||
|
typeClass, //!< Class definition
|
||||||
|
typeNamespace, //!< Namespace definition
|
||||||
|
typeCondition, //!< Classicle condition (with else)
|
||||||
|
typeFor, //!< classicle C cycle (init, inc, condition)
|
||||||
|
typeWhile, //!< Call a cycle (option action previous condition or condition previous action)
|
||||||
|
typeOperator, //!< Call operator "xx" ex : "*" "++" "=" "=="
|
||||||
|
typeReserveId = 5000,
|
||||||
|
};
|
||||||
|
class Element : public std::enable_shared_from_this<Element> {
|
||||||
|
protected:
|
||||||
|
int32_t m_tockenId;
|
||||||
|
public:
|
||||||
|
int32_t getTockenId() {
|
||||||
|
return m_tockenId;
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
Element(int32_t _tockenId=-1) :
|
||||||
|
m_tockenId(_tockenId) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Element() {}
|
||||||
|
};
|
||||||
|
class Block : public Element {
|
||||||
|
protected:
|
||||||
|
std::vector<std::shared_ptr<Element>> m_actions;
|
||||||
|
public:
|
||||||
|
Block() :
|
||||||
|
Element(interpreter::typeBlock) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Block() {}
|
||||||
|
};
|
||||||
|
class Type : public Element {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
Type() :
|
||||||
|
Element(interpreter::typeType) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Type() {}
|
||||||
|
};
|
||||||
|
class Variable : public Element {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
Variable() :
|
||||||
|
Element(interpreter::typeVariable) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Variable() {}
|
||||||
|
};
|
||||||
|
class VariableDeclaration : public Element {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
VariableDeclaration() :
|
||||||
|
Element(interpreter::typeVariableDeclaration) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~VariableDeclaration() {}
|
||||||
|
};
|
||||||
|
class Function : public Element {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
Function() :
|
||||||
|
Element(interpreter::typeFunction) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Function() {}
|
||||||
|
};
|
||||||
|
class Class : public Element {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
Class() :
|
||||||
|
Element(interpreter::typeClass) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Class() {}
|
||||||
|
};
|
||||||
|
class Namespace : public Element {
|
||||||
|
protected:
|
||||||
|
|
||||||
|
public:
|
||||||
|
Namespace() :
|
||||||
|
Element(interpreter::typeNamespace) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Namespace() {}
|
||||||
|
};
|
||||||
|
class Condition : public Element {
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<Element> m_condition;
|
||||||
|
std::shared_ptr<Block> m_block;
|
||||||
|
std::shared_ptr<Block> m_blockElse;
|
||||||
|
public:
|
||||||
|
Condition() :
|
||||||
|
Element(interpreter::typeCondition) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Condition() {}
|
||||||
|
|
||||||
|
};
|
||||||
|
class For : public Element {
|
||||||
|
protected:
|
||||||
|
std::shared_ptr<Element> m_init;
|
||||||
|
std::shared_ptr<Element> m_condition;
|
||||||
|
std::shared_ptr<Element> m_increment;
|
||||||
|
std::shared_ptr<Block> m_block;
|
||||||
|
public:
|
||||||
|
For() :
|
||||||
|
Element(interpreter::typeFor) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~For() {}
|
||||||
|
|
||||||
|
};
|
||||||
|
class While : public Element {
|
||||||
|
protected:
|
||||||
|
bool m_conditionAtStart;
|
||||||
|
std::shared_ptr<Element> m_condition;
|
||||||
|
std::shared_ptr<Element> m_action;
|
||||||
|
public:
|
||||||
|
While() :
|
||||||
|
Element(interpreter::typeWhile) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~While() {}
|
||||||
|
};
|
||||||
|
class Operator : public Element {
|
||||||
|
protected:
|
||||||
|
std::string m_operator;
|
||||||
|
public:
|
||||||
|
Operator() :
|
||||||
|
Element(interpreter::typeOperator) {
|
||||||
|
|
||||||
|
}
|
||||||
|
virtual ~Operator() {}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
class Interpreter {
|
class Interpreter {
|
||||||
public:
|
public:
|
||||||
Interpreter();
|
Interpreter();
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
* @license APACHE-2 (see license file)
|
* @license APACHE-2 (see license file)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <eci/Lexer.h>
|
#include <eci/Lexer.h>
|
||||||
#include <eci/debug.h>
|
#include <eci/debug.h>
|
||||||
|
|
||||||
@ -26,10 +27,10 @@ void eci::Lexer::append(int32_t _tokenId, const std::string& _regularExpression)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void eci::Lexer::appendSection(int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop) {
|
void eci::Lexer::appendSection(int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop, const std::string& _type) {
|
||||||
ECI_INFO("CPP lexer add section [" << _tokenId << "] : '" << _tockenStart << "' .. '" << _tockenStop << "'");
|
ECI_INFO("CPP lexer add section [" << _tokenId << "] : '" << _tockenStart << "' .. '" << _tockenStop << "'");
|
||||||
try {
|
try {
|
||||||
m_searchList.push_back(std::make_shared<eci::Lexer::TypeSection>(_tokenId, _tockenStart, _tockenStop));
|
m_searchList.push_back(std::make_shared<eci::Lexer::TypeSection>(_tokenId, _tockenStart, _tockenStop, _type));
|
||||||
} catch (std::exception e){
|
} catch (std::exception e){
|
||||||
ECI_ERROR(" create reg exp : '" << _tockenStart << "' .. '" << _tockenStop << "' : what:" << e.what());
|
ECI_ERROR(" create reg exp : '" << _tockenStart << "' .. '" << _tockenStop << "' : what:" << e.what());
|
||||||
}
|
}
|
||||||
@ -44,10 +45,10 @@ void eci::Lexer::appendSub(int32_t _tokenIdParrent, int32_t _tokenId, const std:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void eci::Lexer::appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop) {
|
void eci::Lexer::appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop, const std::string& _type) {
|
||||||
ECI_INFO("CPP lexer add section sub : [" << _tokenId << "] [" << _tokenIdParrent << "] '" << _tockenStart << "' .. '" << _tockenStop << "'");
|
ECI_INFO("CPP lexer add section sub : [" << _tokenId << "] [" << _tokenIdParrent << "] '" << _tockenStart << "' .. '" << _tockenStop << "'");
|
||||||
try {
|
try {
|
||||||
m_searchList.push_back(std::make_shared<eci::Lexer::TypeSubSection>(_tokenId, _tokenIdParrent, _tockenStart, _tockenStop));
|
m_searchList.push_back(std::make_shared<eci::Lexer::TypeSubSection>(_tokenId, _tokenIdParrent, _tockenStart, _tockenStop, _type));
|
||||||
} catch (std::exception e){
|
} catch (std::exception e){
|
||||||
ECI_ERROR(" create reg exp : '" << _tockenStart << "' .. '" << _tockenStop << "' : what:" << e.what());
|
ECI_ERROR(" create reg exp : '" << _tockenStart << "' .. '" << _tockenStop << "' : what:" << e.what());
|
||||||
}
|
}
|
||||||
@ -176,9 +177,9 @@ void eci::Lexer::TypeSection::parseSectionCurrent(std::vector<std::shared_ptr<ec
|
|||||||
// agragate the subtoken :
|
// agragate the subtoken :
|
||||||
int32_t startPos = _data[startId]->getStartPos();
|
int32_t startPos = _data[startId]->getStartPos();
|
||||||
int32_t stopPos = _data[iii]->getStopPos();
|
int32_t stopPos = _data[iii]->getStopPos();
|
||||||
std::shared_ptr<eci::LexerNodeContainer> newContainer = std::make_shared<eci::LexerNodeContainer>(m_tockenId, startPos, stopPos);
|
std::shared_ptr<eci::LexerNodeContainer> newContainer = std::make_shared<eci::LexerNodeContainer>(m_tockenId, startPos, stopPos, type);
|
||||||
ECI_VERBOSE(" Agregate: " << startId << " -> " << iii);
|
ECI_VERBOSE(" Agregate: " << startId << " -> " << iii);
|
||||||
newContainer->m_list.insert(newContainer->m_list.begin(), _data.begin()+startId, _data.begin()+iii+1);
|
newContainer->m_list.insert(newContainer->m_list.begin(), _data.begin()+startId+1, _data.begin()+iii);
|
||||||
ECI_VERBOSE(" list size=" << newContainer->m_list.size() << " old=" << _data.size());
|
ECI_VERBOSE(" list size=" << newContainer->m_list.size() << " old=" << _data.size());
|
||||||
_data.erase(_data.begin()+startId, _data.begin()+iii+1);
|
_data.erase(_data.begin()+startId, _data.begin()+iii+1);
|
||||||
ECI_VERBOSE(" list size=" << newContainer->m_list.size() << " old=" << _data.size());
|
ECI_VERBOSE(" list size=" << newContainer->m_list.size() << " old=" << _data.size());
|
||||||
|
34
eci/Lexer.h
34
eci/Lexer.h
@ -14,22 +14,19 @@
|
|||||||
#include <regex>
|
#include <regex>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <eci/Interpreter.h>
|
||||||
|
|
||||||
|
|
||||||
namespace eci {
|
namespace eci {
|
||||||
class LexerNode {
|
class LexerNode : public interpreter::Element {
|
||||||
public:
|
public:
|
||||||
LexerNode(int32_t _tockenId=-1, int32_t _startPos=-1, int32_t _stopPos=-1) :
|
LexerNode(int32_t _tockenId=-1, int32_t _startPos=-1, int32_t _stopPos=-1) :
|
||||||
m_tockenId(_tockenId),
|
interpreter::Element(_tockenId),
|
||||||
m_startPos(_startPos),
|
m_startPos(_startPos),
|
||||||
m_stopPos(_stopPos) {
|
m_stopPos(_stopPos) {
|
||||||
|
|
||||||
}
|
}
|
||||||
virtual ~LexerNode() {};
|
virtual ~LexerNode() {};
|
||||||
int32_t m_tockenId;
|
|
||||||
int32_t getTockenId() {
|
|
||||||
return m_tockenId;
|
|
||||||
}
|
|
||||||
int32_t m_startPos;
|
int32_t m_startPos;
|
||||||
int32_t getStartPos() {
|
int32_t getStartPos() {
|
||||||
return m_startPos;
|
return m_startPos;
|
||||||
@ -43,16 +40,21 @@ namespace eci {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
class LexerNodeContainer : public LexerNode {
|
class LexerNodeContainer : public LexerNode {
|
||||||
|
private:
|
||||||
|
std::string m_type;
|
||||||
public:
|
public:
|
||||||
LexerNodeContainer(int32_t _tockenId=-1, int32_t _startPos=-1, int32_t _stopPos=-1) :
|
LexerNodeContainer(int32_t _tockenId=-1, int32_t _startPos=-1, int32_t _stopPos=-1, const std::string& _type="") :
|
||||||
LexerNode(_tockenId, _startPos, _stopPos) {
|
LexerNode(_tockenId, _startPos, _stopPos) {
|
||||||
|
m_type = _type;
|
||||||
}
|
}
|
||||||
virtual ~LexerNodeContainer() {};
|
virtual ~LexerNodeContainer() {};
|
||||||
std::vector<std::shared_ptr<eci::LexerNode>> m_list;
|
std::vector<std::shared_ptr<eci::LexerNode>> m_list;
|
||||||
virtual bool isNodeContainer() {
|
virtual bool isNodeContainer() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
const std::string& getType() const {
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class LexerResult {
|
class LexerResult {
|
||||||
private:
|
private:
|
||||||
@ -121,10 +123,12 @@ namespace eci {
|
|||||||
public:
|
public:
|
||||||
int32_t tockenStart;
|
int32_t tockenStart;
|
||||||
int32_t tockenStop;
|
int32_t tockenStop;
|
||||||
TypeSection(int32_t _tockenId, int32_t _tockenStart=-1, int32_t _tockenStop=-1) :
|
std::string type;
|
||||||
|
TypeSection(int32_t _tockenId, int32_t _tockenStart=-1, int32_t _tockenStop=-1, const std::string& _type="") :
|
||||||
Type(_tockenId),
|
Type(_tockenId),
|
||||||
tockenStart(_tockenStart),
|
tockenStart(_tockenStart),
|
||||||
tockenStop(_tockenStop) {
|
tockenStop(_tockenStop),
|
||||||
|
type(_type) {
|
||||||
m_regexValue = "tok=" + etk::to_string(tockenStart) + " -> tok=" + etk::to_string(tockenStop);
|
m_regexValue = "tok=" + etk::to_string(tockenStart) + " -> tok=" + etk::to_string(tockenStop);
|
||||||
}
|
}
|
||||||
virtual int32_t getType() {
|
virtual int32_t getType() {
|
||||||
@ -153,8 +157,8 @@ namespace eci {
|
|||||||
class TypeSubSection : public TypeSection {
|
class TypeSubSection : public TypeSection {
|
||||||
public:
|
public:
|
||||||
int32_t parrent;
|
int32_t parrent;
|
||||||
TypeSubSection(int32_t _tockenId, int32_t _tokenIdParrent=-1, int32_t _tockenStart=-1, int32_t _tockenStop=-1) :
|
TypeSubSection(int32_t _tockenId, int32_t _tokenIdParrent=-1, int32_t _tockenStart=-1, int32_t _tockenStop=-1, const std::string& _type="") :
|
||||||
TypeSection(_tockenId, _tockenStart, _tockenStop),
|
TypeSection(_tockenId, _tockenStart, _tockenStop, _type),
|
||||||
parrent(_tokenIdParrent) {}
|
parrent(_tokenIdParrent) {}
|
||||||
virtual int32_t getType() {
|
virtual int32_t getType() {
|
||||||
return TYPE_SUB_SECTION;
|
return TYPE_SUB_SECTION;
|
||||||
@ -179,8 +183,9 @@ namespace eci {
|
|||||||
* @param[in] _tokenId Tocken id value.
|
* @param[in] _tokenId Tocken id value.
|
||||||
* @param[in] _tockenStart Tocken start.
|
* @param[in] _tockenStart Tocken start.
|
||||||
* @param[in] _tockenStop Tocken stop.
|
* @param[in] _tockenStop Tocken stop.
|
||||||
|
* @param[in] _type register type when we parse it ...
|
||||||
*/
|
*/
|
||||||
void appendSection(int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop);
|
void appendSection(int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop, const std::string& _type);
|
||||||
/**
|
/**
|
||||||
* @brief Append a Token recognition (sub parsing).
|
* @brief Append a Token recognition (sub parsing).
|
||||||
* @param[in] _tokenIdParrent parrent Tocken id value.
|
* @param[in] _tokenIdParrent parrent Tocken id value.
|
||||||
@ -194,8 +199,9 @@ namespace eci {
|
|||||||
* @param[in] _tokenId Tocken id value.
|
* @param[in] _tokenId Tocken id value.
|
||||||
* @param[in] _tockenStart Tocken start.
|
* @param[in] _tockenStart Tocken start.
|
||||||
* @param[in] _tockenStop Tocken stop.
|
* @param[in] _tockenStop Tocken stop.
|
||||||
|
* @param[in] _type register type when we parse it ...
|
||||||
*/
|
*/
|
||||||
void appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop);
|
void appendSubSection(int32_t _tokenIdParrent, int32_t _tokenId, int32_t _tockenStart, int32_t _tockenStop, const std::string& _type);
|
||||||
|
|
||||||
LexerResult interprete(const std::string& _data);
|
LexerResult interprete(const std::string& _data);
|
||||||
};
|
};
|
||||||
|
42
eci/Type.h
42
eci/Type.h
@ -10,23 +10,27 @@
|
|||||||
#define __ECI_TYPE_H__
|
#define __ECI_TYPE_H__
|
||||||
|
|
||||||
#include <etk/types.h>
|
#include <etk/types.h>
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <eci/debug.h>
|
||||||
|
|
||||||
namespace eci {
|
namespace eci {
|
||||||
class Type : public std::enable_shared_from_this<Type> {
|
class Variable;
|
||||||
|
class Type : public std::enable_shared_from_this<eci::Type> {
|
||||||
protected:
|
protected:
|
||||||
std::string m_signature; // !!! <== specific au language ...
|
std::string m_signature; // !!! <== specific au language ...
|
||||||
public:
|
public:
|
||||||
Type() {};
|
Type() {};
|
||||||
~Type() {};
|
virtual ~Type() {};
|
||||||
virtual std::shared_ptr<eci::Variable> operator(const std::shared_ptr<eci::Variable>& _this,
|
virtual std::shared_ptr<eci::Variable> callOperator(const std::shared_ptr<eci::Variable>& _this,
|
||||||
const std::string& _operatorName,
|
const std::string& _operatorName,
|
||||||
const std::shared_ptr<eci::Variable>& _obj) {
|
const std::shared_ptr<eci::Variable>& _obj) {
|
||||||
ECI_ERROR("call unknow operator : '" << _operatorName << "'");
|
ECI_ERROR("call unknow operator : '" << _operatorName << "'");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
virtual std::vector<std::shared_ptr<eci::Variable>> call(const std::shared_ptr<eci::Variable>& _this,
|
virtual std::vector<std::shared_ptr<eci::Variable>> callFunction(const std::shared_ptr<eci::Variable>& _this,
|
||||||
const std::string& _name,
|
const std::string& _name,
|
||||||
const std::vector<std::shared_ptr<eci::Variable>>& _objList) {
|
const std::vector<std::shared_ptr<eci::Variable>>& _objList) {
|
||||||
ECI_ERROR("call unknow function : '" << _name << "' with _input.size()=" << _objList.size());
|
ECI_ERROR("call unknow function : '" << _name << "' with _input.size()=" << _objList.size());
|
||||||
return std::vector<std::shared_ptr<eci::Variable>>();
|
return std::vector<std::shared_ptr<eci::Variable>>();
|
||||||
};
|
};
|
||||||
@ -35,15 +39,27 @@ namespace eci {
|
|||||||
ECI_ERROR("try get unknow Variable : '" << _name << "'");
|
ECI_ERROR("try get unknow Variable : '" << _name << "'");
|
||||||
return nullptr;
|
return nullptr;
|
||||||
};
|
};
|
||||||
virtual std::shared_ptr<eci::Variable> create(const std::vector<std::shared_ptr<eci::Variable>>& _obj);
|
virtual std::shared_ptr<eci::Variable> create(const std::vector<std::shared_ptr<eci::Variable>>& _objList) {
|
||||||
virtual std::shared_ptr<eci::Variable> clone(const std::vector<std::shared_ptr<eci::Variable>>& _obj);
|
return nullptr;
|
||||||
|
}
|
||||||
|
virtual void destroy(std::shared_ptr<eci::Variable>& _obj) {
|
||||||
|
if (_obj != nullptr) {
|
||||||
|
// TODO : mark as destroyed ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
virtual std::shared_ptr<eci::Variable> clone(const std::shared_ptr<eci::Variable>& _obj) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
virtual std::shared_ptr<eci::Variable> cast(const std::shared_ptr<eci::Variable>& _obj, const eci::Type& _type) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
class TypeNatif : public Type {
|
class TypeNatif : public Type {
|
||||||
protected:
|
protected:
|
||||||
// name , opertor * / += / ++ ...
|
// name , opertor * / += / ++ ...
|
||||||
std::map<std::string, std::function<std::shared_ptr<eci::Variable>, std::shared_ptr<eci::Variable> _variable>> m_operatorList;
|
std::map<std::string, std::function<std::shared_ptr<eci::Variable>(const std::shared_ptr<eci::Variable>&)>> m_operatorList;
|
||||||
// name , function to call
|
// name , function to call
|
||||||
std::map<std::string, std::function<std::vector<std::shared_ptr<eci::Variable>>, std::vector<std::shared_ptr<eci::Variable>> _variable>> m_functionList;
|
std::map<std::string, std::function<std::vector<std::shared_ptr<eci::Variable>>(const std::vector<std::shared_ptr<eci::Variable>>&)>> m_functionList;
|
||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
@ -55,7 +71,7 @@ namespace eci {
|
|||||||
|
|
||||||
template<> class TypeBase<int32_t> {
|
template<> class TypeBase<int32_t> {
|
||||||
|
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -12,13 +12,14 @@
|
|||||||
#include <etk/types.h>
|
#include <etk/types.h>
|
||||||
#include <eci/visibility.h>
|
#include <eci/visibility.h>
|
||||||
#include <eci/Type.h>
|
#include <eci/Type.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
namespace eci {
|
namespace eci {
|
||||||
class Variable : public std::enable_shared_from_this<Variable> {
|
class Variable : public std::enable_shared_from_this<Variable> {
|
||||||
public:
|
public:
|
||||||
Variable();
|
Variable();
|
||||||
~Variable();
|
virtual ~Variable();
|
||||||
private:
|
private:
|
||||||
enum eci::visibility m_visibility;
|
enum eci::visibility m_visibility;
|
||||||
bool m_const;
|
bool m_const;
|
||||||
|
@ -48,9 +48,9 @@ eci::ParserCpp::ParserCpp() {
|
|||||||
m_lexer.append(tokenCppAssignation, "(\\+=|-=|\\*=|/=|=|\\*|/|--|-|\\+\\+|\\+|&)");
|
m_lexer.append(tokenCppAssignation, "(\\+=|-=|\\*=|/=|=|\\*|/|--|-|\\+\\+|\\+|&)");
|
||||||
m_lexer.append(tokenCppString, "\\w+");
|
m_lexer.append(tokenCppString, "\\w+");
|
||||||
m_lexer.append(tokenCppSeparator, "(;|,|::|:)");
|
m_lexer.append(tokenCppSeparator, "(;|,|::|:)");
|
||||||
m_lexer.appendSection(tokenCppSectionBrace, tokenCppBraceIn, tokenCppBraceOut);
|
m_lexer.appendSection(tokenCppSectionBrace, tokenCppBraceIn, tokenCppBraceOut, "{}");
|
||||||
m_lexer.appendSection(tokenCppSectionPthese, tokenCppPtheseIn, tokenCppPtheseOut);
|
m_lexer.appendSection(tokenCppSectionPthese, tokenCppPtheseIn, tokenCppPtheseOut, "()");
|
||||||
m_lexer.appendSection(tokenCppSectionHook, tokenCppHookIn, tokenCppHookOut);
|
m_lexer.appendSection(tokenCppSectionHook, tokenCppHookIn, tokenCppHookOut, "[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
eci::ParserCpp::~ParserCpp() {
|
eci::ParserCpp::~ParserCpp() {
|
||||||
@ -66,7 +66,7 @@ static void printNode(const std::string& _data, const std::vector<std::shared_pt
|
|||||||
if (it->isNodeContainer() == true) {
|
if (it->isNodeContainer() == true) {
|
||||||
std::shared_ptr<eci::LexerNodeContainer> sec = std::dynamic_pointer_cast<eci::LexerNodeContainer>(it);
|
std::shared_ptr<eci::LexerNodeContainer> sec = std::dynamic_pointer_cast<eci::LexerNodeContainer>(it);
|
||||||
if (sec != nullptr) {
|
if (sec != nullptr) {
|
||||||
ECI_INFO(offset << " " << it->getStartPos() << "->" << it->getStopPos() << " (container)");
|
ECI_INFO(offset << " " << sec->getStartPos() << "->" << sec->getStopPos() << " container: " << sec->getType());
|
||||||
printNode(_data, sec->m_list, _level+1);
|
printNode(_data, sec->m_list, _level+1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,11 +10,12 @@
|
|||||||
#define __ECI_PARSER_CPP_H__
|
#define __ECI_PARSER_CPP_H__
|
||||||
|
|
||||||
#include <eci/Lexer.h>
|
#include <eci/Lexer.h>
|
||||||
|
#include <eci/Interpreter.h>
|
||||||
|
|
||||||
namespace eci {
|
namespace eci {
|
||||||
|
|
||||||
enum cppTokenList {
|
enum cppTokenList {
|
||||||
tokenCppCommentMultiline,
|
tokenCppCommentMultiline = interpreter::typeReserveId,
|
||||||
tokenCppCommentSingleLine,
|
tokenCppCommentSingleLine,
|
||||||
tokenCppPreProcessor,
|
tokenCppPreProcessor,
|
||||||
tokenCppPreProcessorIf,
|
tokenCppPreProcessorIf,
|
||||||
|
@ -30,9 +30,9 @@ eci::ParserJS::ParserJS() {
|
|||||||
m_lexer.append(tokenJSAssignation, "(\\+=|-=|\\*=|/=|=|\\*|/|--|-|\\+\\+|\\+|&)");
|
m_lexer.append(tokenJSAssignation, "(\\+=|-=|\\*=|/=|=|\\*|/|--|-|\\+\\+|\\+|&)");
|
||||||
m_lexer.append(tokenJSString, "\\w+");
|
m_lexer.append(tokenJSString, "\\w+");
|
||||||
m_lexer.append(tokenJSSeparator, "(;|,)");
|
m_lexer.append(tokenJSSeparator, "(;|,)");
|
||||||
m_lexer.appendSection(tokenJSSectionBrace, tokenJSBraceIn, tokenJSBraceOut);
|
m_lexer.appendSection(tokenJSSectionBrace, tokenJSBraceIn, tokenJSBraceOut, "{}");
|
||||||
m_lexer.appendSection(tokenJSSectionPthese, tokenJSPtheseIn, tokenJSPtheseOut);
|
m_lexer.appendSection(tokenJSSectionPthese, tokenJSPtheseIn, tokenJSPtheseOut, "()");
|
||||||
m_lexer.appendSection(tokenJSSectionHook, tokenJSHookIn, tokenJSHookOut);
|
m_lexer.appendSection(tokenJSSectionHook, tokenJSHookIn, tokenJSHookOut, "[]");
|
||||||
}
|
}
|
||||||
|
|
||||||
eci::ParserJS::~ParserJS() {
|
eci::ParserJS::~ParserJS() {
|
||||||
@ -48,7 +48,7 @@ static void printNode(const std::string& _data, const std::vector<std::shared_pt
|
|||||||
if (it->isNodeContainer() == true) {
|
if (it->isNodeContainer() == true) {
|
||||||
std::shared_ptr<eci::LexerNodeContainer> sec = std::dynamic_pointer_cast<eci::LexerNodeContainer>(it);
|
std::shared_ptr<eci::LexerNodeContainer> sec = std::dynamic_pointer_cast<eci::LexerNodeContainer>(it);
|
||||||
if (sec != nullptr) {
|
if (sec != nullptr) {
|
||||||
ECI_INFO(offset << " " << it->getStartPos() << "->" << it->getStopPos() << " (container)");
|
ECI_INFO(offset << " " << sec->getStartPos() << "->" << sec->getStopPos() << " container: " << sec->getType());
|
||||||
printNode(_data, sec->m_list, _level+1);
|
printNode(_data, sec->m_list, _level+1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -10,11 +10,12 @@
|
|||||||
#define __ECI_PARSER_JS_H__
|
#define __ECI_PARSER_JS_H__
|
||||||
|
|
||||||
#include <eci/Lexer.h>
|
#include <eci/Lexer.h>
|
||||||
|
#include <eci/Interpreter.h>
|
||||||
|
|
||||||
namespace eci {
|
namespace eci {
|
||||||
|
|
||||||
enum jsTokenList {
|
enum jsTokenList {
|
||||||
tokenJSCommentMultiline,
|
tokenJSCommentMultiline = interpreter::typeReserveId,
|
||||||
tokenJSCommentSingleLine,
|
tokenJSCommentSingleLine,
|
||||||
|
|
||||||
tokenJSStringDoubleQuote,
|
tokenJSStringDoubleQuote,
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a;
|
|
||||||
a = 42;
|
|
||||||
printf("%d\n", a);
|
|
||||||
|
|
||||||
int b = 64;
|
|
||||||
printf("%d\n", b);
|
|
||||||
|
|
||||||
int c = 12, d = 34;
|
|
||||||
printf("%d, %d\n", c, d);
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,3 +0,0 @@
|
|||||||
42
|
|
||||||
64
|
|
||||||
12, 34
|
|
@ -1,11 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
printf("Hello 1\n");
|
|
||||||
printf("Hello 2\n"); /* this is a comment */ printf("Hello 3\n");
|
|
||||||
printf("Hello 4\n");
|
|
||||||
// this is also a comment sayhello();
|
|
||||||
printf("Hello 5\n");
|
|
||||||
printf("Hello 6\n"); /* this is a second comment */ printf("Hello 7\n");
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,7 +0,0 @@
|
|||||||
Hello 1
|
|
||||||
Hello 2
|
|
||||||
Hello 3
|
|
||||||
Hello 4
|
|
||||||
Hello 5
|
|
||||||
Hello 6
|
|
||||||
Hello 7
|
|
@ -1,13 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
printf("Hello world\n");
|
|
||||||
|
|
||||||
int Count;
|
|
||||||
for (Count = -5; Count <= 5; Count++)
|
|
||||||
printf("Count = %d\n", Count);
|
|
||||||
|
|
||||||
printf("String 'hello', 'there' is '%s', '%s'\n", "hello", "there");
|
|
||||||
printf("Character 'A' is '%c'\n", 65);
|
|
||||||
printf("Character 'a' is '%c'\n", 'a');
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,15 +0,0 @@
|
|||||||
Hello world
|
|
||||||
Count = -5
|
|
||||||
Count = -4
|
|
||||||
Count = -3
|
|
||||||
Count = -2
|
|
||||||
Count = -1
|
|
||||||
Count = 0
|
|
||||||
Count = 1
|
|
||||||
Count = 2
|
|
||||||
Count = 3
|
|
||||||
Count = 4
|
|
||||||
Count = 5
|
|
||||||
String 'hello', 'there' is 'hello', 'there'
|
|
||||||
Character 'A' is 'A'
|
|
||||||
Character 'a' is 'a'
|
|
@ -1,21 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
struct fred
|
|
||||||
{
|
|
||||||
int boris;
|
|
||||||
int natasha;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct fred bloggs;
|
|
||||||
|
|
||||||
bloggs.boris = 12;
|
|
||||||
bloggs.natasha = 34;
|
|
||||||
|
|
||||||
printf("%d\n", bloggs.boris);
|
|
||||||
printf("%d\n", bloggs.natasha);
|
|
||||||
|
|
||||||
//struct fred jones[2];
|
|
||||||
//jones[0].boris = 12;
|
|
||||||
//jones[0].natasha = 34;
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,2 +0,0 @@
|
|||||||
12
|
|
||||||
34
|
|
@ -1,10 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int Count;
|
|
||||||
|
|
||||||
for (Count = 1; Count <= 10; Count++)
|
|
||||||
{
|
|
||||||
printf("%d\n", Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,10 +0,0 @@
|
|||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
4
|
|
||||||
5
|
|
||||||
6
|
|
||||||
7
|
|
||||||
8
|
|
||||||
9
|
|
||||||
10
|
|
@ -1,16 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int Count;
|
|
||||||
int Array[10];
|
|
||||||
|
|
||||||
for (Count = 1; Count <= 10; Count++)
|
|
||||||
{
|
|
||||||
Array[Count-1] = Count * Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Count = 0; Count < 10; Count++)
|
|
||||||
{
|
|
||||||
printf("%d\n", Array[Count]);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,10 +0,0 @@
|
|||||||
1
|
|
||||||
4
|
|
||||||
9
|
|
||||||
16
|
|
||||||
25
|
|
||||||
36
|
|
||||||
49
|
|
||||||
64
|
|
||||||
81
|
|
||||||
100
|
|
@ -1,24 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int Count;
|
|
||||||
|
|
||||||
for (Count = 0; Count < 4; Count++)
|
|
||||||
{
|
|
||||||
printf("%d\n", Count);
|
|
||||||
switch (Count)
|
|
||||||
{
|
|
||||||
case 1:
|
|
||||||
printf("%d\n", 1);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
printf("%d\n", 2);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
printf("%d\n", 0);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,8 +0,0 @@
|
|||||||
0
|
|
||||||
0
|
|
||||||
1
|
|
||||||
1
|
|
||||||
2
|
|
||||||
2
|
|
||||||
3
|
|
||||||
0
|
|
@ -1,25 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int myfunc(int x)
|
|
||||||
{
|
|
||||||
return x * x;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("%d\n", myfunc(3));
|
|
||||||
printf("%d\n", myfunc(4));
|
|
||||||
|
|
||||||
void vfunc(int a)
|
|
||||||
{
|
|
||||||
printf("a=%d\n", a);
|
|
||||||
}
|
|
||||||
|
|
||||||
vfunc(1234);
|
|
||||||
|
|
||||||
void qfunc()
|
|
||||||
{
|
|
||||||
printf("qfunc()\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
qfunc();
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,4 +0,0 @@
|
|||||||
9
|
|
||||||
16
|
|
||||||
a=1234
|
|
||||||
qfunc()
|
|
@ -1,19 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a;
|
|
||||||
int p;
|
|
||||||
int t;
|
|
||||||
|
|
||||||
a = 1;
|
|
||||||
p = 0;
|
|
||||||
t = 0;
|
|
||||||
|
|
||||||
while (a < 100)
|
|
||||||
{
|
|
||||||
printf("%d\n", a);
|
|
||||||
t = a;
|
|
||||||
a = t + p;
|
|
||||||
p = t;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,11 +0,0 @@
|
|||||||
1
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
5
|
|
||||||
8
|
|
||||||
13
|
|
||||||
21
|
|
||||||
34
|
|
||||||
55
|
|
||||||
89
|
|
@ -1,20 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a;
|
|
||||||
int p;
|
|
||||||
int t;
|
|
||||||
|
|
||||||
a = 1;
|
|
||||||
p = 0;
|
|
||||||
t = 0;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
printf("%d\n", a);
|
|
||||||
t = a;
|
|
||||||
a = t + p;
|
|
||||||
p = t;
|
|
||||||
} while (a < 100);
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,11 +0,0 @@
|
|||||||
1
|
|
||||||
1
|
|
||||||
2
|
|
||||||
3
|
|
||||||
5
|
|
||||||
8
|
|
||||||
13
|
|
||||||
21
|
|
||||||
34
|
|
||||||
55
|
|
||||||
89
|
|
@ -1,37 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a;
|
|
||||||
int *b;
|
|
||||||
int c;
|
|
||||||
|
|
||||||
a = 42;
|
|
||||||
b = &a;
|
|
||||||
printf("a = %d\n", *b);
|
|
||||||
|
|
||||||
struct ziggy
|
|
||||||
{
|
|
||||||
int a;
|
|
||||||
int b;
|
|
||||||
int c;
|
|
||||||
} bolshevic;
|
|
||||||
|
|
||||||
bolshevic.a = 12;
|
|
||||||
bolshevic.b = 34;
|
|
||||||
bolshevic.c = 56;
|
|
||||||
|
|
||||||
printf("bolshevic.a = %d\n", bolshevic.a);
|
|
||||||
printf("bolshevic.b = %d\n", bolshevic.b);
|
|
||||||
printf("bolshevic.c = %d\n", bolshevic.c);
|
|
||||||
|
|
||||||
struct ziggy *tsar = &bolshevic;
|
|
||||||
|
|
||||||
printf("tsar->a = %d\n", tsar->a);
|
|
||||||
printf("tsar->b = %d\n", tsar->b);
|
|
||||||
printf("tsar->c = %d\n", tsar->c);
|
|
||||||
|
|
||||||
/*
|
|
||||||
b = &(bolshevic.b);
|
|
||||||
printf("bolshevic.b = %d\n", *b);
|
|
||||||
*/
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,7 +0,0 @@
|
|||||||
a = 42
|
|
||||||
bolshevic.a = 12
|
|
||||||
bolshevic.b = 34
|
|
||||||
bolshevic.c = 56
|
|
||||||
tsar->a = 12
|
|
||||||
tsar->b = 34
|
|
||||||
tsar->c = 56
|
|
@ -1,38 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a;
|
|
||||||
int b;
|
|
||||||
int c;
|
|
||||||
int d;
|
|
||||||
int e;
|
|
||||||
int f;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
|
|
||||||
a = 12;
|
|
||||||
b = 34;
|
|
||||||
c = 56;
|
|
||||||
d = 78;
|
|
||||||
e = 0;
|
|
||||||
f = 1;
|
|
||||||
|
|
||||||
printf("%d\n", c + d);
|
|
||||||
printf("%d\n", (y = c + d));
|
|
||||||
/* printf("%d\n", a ? b+c : c+d);
|
|
||||||
printf("%d\n", a ? b+c : c+d);
|
|
||||||
printf("%d\n", a || b ? b+c : c+d); */
|
|
||||||
printf("%d\n", e || e && f);
|
|
||||||
printf("%d\n", e || f && f);
|
|
||||||
printf("%d\n", e && e || f);
|
|
||||||
printf("%d\n", e && f || f);
|
|
||||||
printf("%d\n", a && f | f);
|
|
||||||
printf("%d\n", a | b ^ c & d);
|
|
||||||
printf("%d, %d\n", a == a, a == b);
|
|
||||||
printf("%d, %d\n", a != a, a != b);
|
|
||||||
printf("%d\n", a != b && c != d);
|
|
||||||
printf("%d\n", a + b * c / f);
|
|
||||||
printf("%d\n", a + b * c / f);
|
|
||||||
printf("%d\n", (4 << 4));
|
|
||||||
printf("%d\n", (64 >> 4));
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,15 +0,0 @@
|
|||||||
134
|
|
||||||
134
|
|
||||||
0
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
46
|
|
||||||
1, 0
|
|
||||||
0, 1
|
|
||||||
1
|
|
||||||
1916
|
|
||||||
1916
|
|
||||||
64
|
|
||||||
4
|
|
@ -1,10 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define FRED 12
|
|
||||||
#define BLOGGS(x) (12*(x))
|
|
||||||
|
|
||||||
printf("%d\n", FRED);
|
|
||||||
printf("%d, %d, %d\n", BLOGGS(1), BLOGGS(2), BLOGGS(3));
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,2 +0,0 @@
|
|||||||
12
|
|
||||||
12, 24, 36
|
|
@ -1,16 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a = 24680;
|
|
||||||
int b = 01234567;
|
|
||||||
int c = 0x2468ac;
|
|
||||||
int d = 0x2468AC;
|
|
||||||
int e = 0b010101010101;
|
|
||||||
|
|
||||||
printf("%d\n", a);
|
|
||||||
printf("%d\n", b);
|
|
||||||
printf("%d\n", c);
|
|
||||||
printf("%d\n", d);
|
|
||||||
printf("%d\n", e);
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,5 +0,0 @@
|
|||||||
24680
|
|
||||||
342391
|
|
||||||
2386092
|
|
||||||
2386092
|
|
||||||
1365
|
|
@ -1,17 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a = 1;
|
|
||||||
|
|
||||||
if (a)
|
|
||||||
printf("a is true\n");
|
|
||||||
else
|
|
||||||
printf("a is false\n");
|
|
||||||
|
|
||||||
int b = 0;
|
|
||||||
if (b)
|
|
||||||
printf("b is true\n");
|
|
||||||
else
|
|
||||||
printf("b is false\n");
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,2 +0,0 @@
|
|||||||
a is true
|
|
||||||
b is false
|
|
@ -1,16 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int factorial(int i)
|
|
||||||
{
|
|
||||||
if (i < 2)
|
|
||||||
return i;
|
|
||||||
else
|
|
||||||
return i * factorial(i - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Count;
|
|
||||||
|
|
||||||
for (Count = 1; Count <= 10; Count++)
|
|
||||||
printf("%d\n", factorial(Count));
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,10 +0,0 @@
|
|||||||
1
|
|
||||||
2
|
|
||||||
6
|
|
||||||
24
|
|
||||||
120
|
|
||||||
720
|
|
||||||
5040
|
|
||||||
40320
|
|
||||||
362880
|
|
||||||
3628800
|
|
@ -1,16 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int x, y, z;
|
|
||||||
|
|
||||||
for (x = 0; x < 2; x++)
|
|
||||||
{
|
|
||||||
for (y = 0; y < 3; y++)
|
|
||||||
{
|
|
||||||
for (z = 0; z < 3; z++)
|
|
||||||
{
|
|
||||||
printf("%d %d %d\n", x, y, z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,18 +0,0 @@
|
|||||||
0 0 0
|
|
||||||
0 0 1
|
|
||||||
0 0 2
|
|
||||||
0 1 0
|
|
||||||
0 1 1
|
|
||||||
0 1 2
|
|
||||||
0 2 0
|
|
||||||
0 2 1
|
|
||||||
0 2 2
|
|
||||||
1 0 0
|
|
||||||
1 0 1
|
|
||||||
1 0 2
|
|
||||||
1 1 0
|
|
||||||
1 1 1
|
|
||||||
1 1 2
|
|
||||||
1 2 0
|
|
||||||
1 2 1
|
|
||||||
1 2 2
|
|
@ -1,24 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
enum fred
|
|
||||||
{
|
|
||||||
a,
|
|
||||||
b,
|
|
||||||
c,
|
|
||||||
d,
|
|
||||||
e = 54,
|
|
||||||
f = 73,
|
|
||||||
g,
|
|
||||||
h
|
|
||||||
};
|
|
||||||
|
|
||||||
enum fred frod;
|
|
||||||
|
|
||||||
printf("%d %d %d %d %d %d %d %d\n", a, b, c, d, e, f, g, h);
|
|
||||||
printf("%d\n", frod);
|
|
||||||
frod = 12;
|
|
||||||
printf("%d\n", frod);
|
|
||||||
frod = e;
|
|
||||||
printf("%d\n", frod);
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,4 +0,0 @@
|
|||||||
0 1 2 3 54 73 74 75
|
|
||||||
0
|
|
||||||
12
|
|
||||||
54
|
|
@ -1,7 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
printf("including\n");
|
|
||||||
#include "18_include.h"
|
|
||||||
printf("done\n");
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,3 +0,0 @@
|
|||||||
including
|
|
||||||
included
|
|
||||||
done
|
|
@ -1 +0,0 @@
|
|||||||
printf("included\n");
|
|
@ -1,24 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a;
|
|
||||||
int *b;
|
|
||||||
int *c;
|
|
||||||
|
|
||||||
a = 42;
|
|
||||||
b = &a;
|
|
||||||
c = NULL;
|
|
||||||
|
|
||||||
printf("%d\n", *b);
|
|
||||||
|
|
||||||
if (b == NULL)
|
|
||||||
printf("b is NULL\n");
|
|
||||||
else
|
|
||||||
printf("b is not NULL\n");
|
|
||||||
|
|
||||||
if (c == NULL)
|
|
||||||
printf("c is NULL\n");
|
|
||||||
else
|
|
||||||
printf("c is not NULL\n");
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,3 +0,0 @@
|
|||||||
42
|
|
||||||
b is not NULL
|
|
||||||
c is NULL
|
|
@ -1,20 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a;
|
|
||||||
int b;
|
|
||||||
int *d;
|
|
||||||
int *e;
|
|
||||||
d = &a;
|
|
||||||
e = &b;
|
|
||||||
a = 12;
|
|
||||||
b = 34;
|
|
||||||
printf("%d\n", *d);
|
|
||||||
printf("%d\n", *e);
|
|
||||||
printf("%d\n", d == e);
|
|
||||||
printf("%d\n", d != e);
|
|
||||||
d = e;
|
|
||||||
printf("%d\n", d == e);
|
|
||||||
printf("%d\n", d != e);
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,6 +0,0 @@
|
|||||||
12
|
|
||||||
34
|
|
||||||
0
|
|
||||||
1
|
|
||||||
1
|
|
||||||
0
|
|
@ -1,29 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int x = 'a';
|
|
||||||
char y = x;
|
|
||||||
|
|
||||||
char *a = "hello";
|
|
||||||
|
|
||||||
printf("%s\n", a);
|
|
||||||
|
|
||||||
int c;
|
|
||||||
c = *a;
|
|
||||||
|
|
||||||
char *b;
|
|
||||||
for (b = a; *b != 0; b++)
|
|
||||||
printf("%c: %d\n", *b, *b);
|
|
||||||
|
|
||||||
char destarray[10];
|
|
||||||
char *dest = &destarray[0];
|
|
||||||
char *src = a;
|
|
||||||
|
|
||||||
while (*src != 0)
|
|
||||||
*dest++ = *src++;
|
|
||||||
|
|
||||||
*dest = 0;
|
|
||||||
|
|
||||||
printf("copied string is %s\n", destarray);
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,7 +0,0 @@
|
|||||||
hello
|
|
||||||
h: 104
|
|
||||||
e: 101
|
|
||||||
l: 108
|
|
||||||
l: 108
|
|
||||||
o: 111
|
|
||||||
copied string is hello
|
|
@ -1,45 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
// variables
|
|
||||||
float a = 12.34 + 56.78;
|
|
||||||
printf("%f\n", a);
|
|
||||||
|
|
||||||
// infix operators
|
|
||||||
printf("%f\n", 12.34 + 56.78);
|
|
||||||
printf("%f\n", 12.34 - 56.78);
|
|
||||||
printf("%f\n", 12.34 * 56.78);
|
|
||||||
printf("%f\n", 12.34 / 56.78);
|
|
||||||
|
|
||||||
// comparison operators
|
|
||||||
printf("%d %d %d %d %d %d\n", 12.34 < 56.78, 12.34 <= 56.78, 12.34 == 56.78, 12.34 >= 56.78, 12.34 > 56.78, 12.34 != 56.78);
|
|
||||||
printf("%d %d %d %d %d %d\n", 12.34 < 12.34, 12.34 <= 12.34, 12.34 == 12.34, 12.34 >= 12.34, 12.34 > 12.34, 12.34 != 12.34);
|
|
||||||
printf("%d %d %d %d %d %d\n", 56.78 < 12.34, 56.78 <= 12.34, 56.78 == 12.34, 56.78 >= 12.34, 56.78 > 12.34, 56.78 != 12.34);
|
|
||||||
|
|
||||||
// assignment operators
|
|
||||||
a = 12.34;
|
|
||||||
a += 56.78;
|
|
||||||
printf("%f\n", a);
|
|
||||||
|
|
||||||
a = 12.34;
|
|
||||||
a -= 56.78;
|
|
||||||
printf("%f\n", a);
|
|
||||||
|
|
||||||
a = 12.34;
|
|
||||||
a *= 56.78;
|
|
||||||
printf("%f\n", a);
|
|
||||||
|
|
||||||
a = 12.34;
|
|
||||||
a /= 56.78;
|
|
||||||
printf("%f\n", a);
|
|
||||||
|
|
||||||
// prefix operators
|
|
||||||
printf("%f\n", +12.34);
|
|
||||||
printf("%f\n", -12.34);
|
|
||||||
|
|
||||||
// type coercion
|
|
||||||
a = 2;
|
|
||||||
printf("%f\n", a);
|
|
||||||
printf("%f\n", sin(2));
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,16 +0,0 @@
|
|||||||
69.120000
|
|
||||||
69.120000
|
|
||||||
-44.440000
|
|
||||||
700.665200
|
|
||||||
0.217330
|
|
||||||
1 1 0 0 0 1
|
|
||||||
0 1 1 1 0 0
|
|
||||||
0 0 0 1 1 1
|
|
||||||
69.120000
|
|
||||||
-44.440000
|
|
||||||
700.665200
|
|
||||||
0.217330
|
|
||||||
12.340000
|
|
||||||
-12.340000
|
|
||||||
2.000000
|
|
||||||
0.909297
|
|
@ -1,49 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void charfunc(char a)
|
|
||||||
{
|
|
||||||
printf("char: %c\n", a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void intfunc(int a)
|
|
||||||
{
|
|
||||||
printf("int: %d\n", a);
|
|
||||||
}
|
|
||||||
|
|
||||||
void floatfunc(float a)
|
|
||||||
{
|
|
||||||
printf("float: %f\n", a);
|
|
||||||
}
|
|
||||||
|
|
||||||
charfunc('a');
|
|
||||||
charfunc(98);
|
|
||||||
charfunc(99.0);
|
|
||||||
|
|
||||||
intfunc('a');
|
|
||||||
intfunc(98);
|
|
||||||
intfunc(99.0);
|
|
||||||
|
|
||||||
floatfunc('a');
|
|
||||||
floatfunc(98);
|
|
||||||
floatfunc(99.0);
|
|
||||||
|
|
||||||
printf("%c %d %f\n", 'a', 'b', 'c');
|
|
||||||
printf("%c %d %f\n", 97, 98, 99);
|
|
||||||
printf("%c %d %f\n", 97.0, 98.0, 99.0);
|
|
||||||
|
|
||||||
char b = 97;
|
|
||||||
char c = 97.0;
|
|
||||||
|
|
||||||
printf("%d %d\n", b, c);
|
|
||||||
|
|
||||||
int d = 'a';
|
|
||||||
int e = 97.0;
|
|
||||||
|
|
||||||
printf("%d %d\n", d, e);
|
|
||||||
|
|
||||||
float f = 'a';
|
|
||||||
float g = 97;
|
|
||||||
|
|
||||||
printf("%f %f\n", f, g);
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,15 +0,0 @@
|
|||||||
char: a
|
|
||||||
char: b
|
|
||||||
char: c
|
|
||||||
int: 97
|
|
||||||
int: 98
|
|
||||||
int: 99
|
|
||||||
float: 97.000000
|
|
||||||
float: 98.000000
|
|
||||||
float: 99.000000
|
|
||||||
a 98 99.000000
|
|
||||||
a 98 99.000000
|
|
||||||
a 98 99.000000
|
|
||||||
97 97
|
|
||||||
97 97
|
|
||||||
97.000000 97.000000
|
|
@ -1,23 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <math.h>
|
|
||||||
|
|
||||||
printf("%f\n", sin(0.12));
|
|
||||||
printf("%f\n", cos(0.12));
|
|
||||||
printf("%f\n", tan(0.12));
|
|
||||||
printf("%f\n", asin(0.12));
|
|
||||||
printf("%f\n", acos(0.12));
|
|
||||||
printf("%f\n", atan(0.12));
|
|
||||||
printf("%f\n", sinh(0.12));
|
|
||||||
printf("%f\n", cosh(0.12));
|
|
||||||
printf("%f\n", tanh(0.12));
|
|
||||||
printf("%f\n", exp(0.12));
|
|
||||||
printf("%f\n", fabs(-0.12));
|
|
||||||
printf("%f\n", log(0.12));
|
|
||||||
printf("%f\n", log10(0.12));
|
|
||||||
printf("%f\n", pow(0.12, 0.12));
|
|
||||||
printf("%f\n", sqrt(0.12));
|
|
||||||
printf("%f\n", round(12.34));
|
|
||||||
printf("%f\n", ceil(12.34));
|
|
||||||
printf("%f\n", floor(12.34));
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,18 +0,0 @@
|
|||||||
0.119712
|
|
||||||
0.992809
|
|
||||||
0.120579
|
|
||||||
0.120290
|
|
||||||
1.450506
|
|
||||||
0.119429
|
|
||||||
0.120288
|
|
||||||
1.007209
|
|
||||||
0.119427
|
|
||||||
1.127497
|
|
||||||
0.120000
|
|
||||||
-2.120264
|
|
||||||
-0.920819
|
|
||||||
0.775357
|
|
||||||
0.346410
|
|
||||||
12.000000
|
|
||||||
13.000000
|
|
||||||
12.000000
|
|
@ -1,80 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int array[16];
|
|
||||||
|
|
||||||
//Swap integer values by array indexes
|
|
||||||
void swap(int a, int b)
|
|
||||||
{
|
|
||||||
int tmp = array[a];
|
|
||||||
array[a] = array[b];
|
|
||||||
array[b] = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Partition the array into two halves and return the
|
|
||||||
//index about which the array is partitioned
|
|
||||||
int partition(int left, int right)
|
|
||||||
{
|
|
||||||
int pivotIndex = left;
|
|
||||||
int pivotValue = array[pivotIndex];
|
|
||||||
int index = left;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
swap(pivotIndex, right);
|
|
||||||
for(i = left; i < right; i++)
|
|
||||||
{
|
|
||||||
if(array[i] < pivotValue)
|
|
||||||
{
|
|
||||||
swap(i, index);
|
|
||||||
index += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
swap(right, index);
|
|
||||||
|
|
||||||
return index;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Quicksort the array
|
|
||||||
void quicksort(int left, int right)
|
|
||||||
{
|
|
||||||
if(left >= right)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int index = partition(left, right);
|
|
||||||
quicksort(left, index - 1);
|
|
||||||
quicksort(index + 1, right);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
array[0] = 62;
|
|
||||||
array[1] = 83;
|
|
||||||
array[2] = 4;
|
|
||||||
array[3] = 89;
|
|
||||||
array[4] = 36;
|
|
||||||
array[5] = 21;
|
|
||||||
array[6] = 74;
|
|
||||||
array[7] = 37;
|
|
||||||
array[8] = 65;
|
|
||||||
array[9] = 33;
|
|
||||||
array[10] = 96;
|
|
||||||
array[11] = 38;
|
|
||||||
array[12] = 53;
|
|
||||||
array[13] = 16;
|
|
||||||
array[14] = 74;
|
|
||||||
array[15] = 55;
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
printf("%d ", array[i]);
|
|
||||||
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
quicksort(0, 15);
|
|
||||||
|
|
||||||
for (i = 0; i < 16; i++)
|
|
||||||
printf("%d ", array[i]);
|
|
||||||
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
@ -1,2 +0,0 @@
|
|||||||
62 83 4 89 36 21 74 37 65 33 96 38 53 16 74 55
|
|
||||||
4 16 21 33 36 37 38 53 55 62 65 74 74 83 89 96
|
|
@ -1,13 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
printf("%d\n", '\1');
|
|
||||||
printf("%d\n", '\10');
|
|
||||||
printf("%d\n", '\100');
|
|
||||||
printf("%d\n", '\x01');
|
|
||||||
printf("%d\n", '\x0e');
|
|
||||||
printf("%d\n", '\x10');
|
|
||||||
printf("%d\n", '\x40');
|
|
||||||
printf("test \x407\n");
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,8 +0,0 @@
|
|||||||
1
|
|
||||||
8
|
|
||||||
64
|
|
||||||
1
|
|
||||||
14
|
|
||||||
16
|
|
||||||
64
|
|
||||||
test @7
|
|
@ -1,12 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
char a;
|
|
||||||
int b;
|
|
||||||
double c;
|
|
||||||
|
|
||||||
printf("%d\n", sizeof(a));
|
|
||||||
printf("%d\n", sizeof(b));
|
|
||||||
printf("%d\n", sizeof(c));
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,3 +0,0 @@
|
|||||||
1
|
|
||||||
4
|
|
||||||
8
|
|
@ -1,41 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char a[10];
|
|
||||||
|
|
||||||
strcpy(a, "hello");
|
|
||||||
printf("%s\n", a);
|
|
||||||
|
|
||||||
strncpy(a, "gosh", 2);
|
|
||||||
printf("%s\n", a);
|
|
||||||
|
|
||||||
printf("%d\n", strcmp(a, "apple") > 0);
|
|
||||||
printf("%d\n", strcmp(a, "goere") > 0);
|
|
||||||
printf("%d\n", strcmp(a, "zebra") < 0);
|
|
||||||
|
|
||||||
printf("%d\n", strlen(a));
|
|
||||||
|
|
||||||
strcat(a, "!");
|
|
||||||
printf("%s\n", a);
|
|
||||||
|
|
||||||
printf("%d\n", strncmp(a, "apple", 2) > 0);
|
|
||||||
printf("%d\n", strncmp(a, "goere", 2) == 0);
|
|
||||||
printf("%d\n", strncmp(a, "goerg", 2) == 0);
|
|
||||||
printf("%d\n", strncmp(a, "zebra", 2) < 0);
|
|
||||||
|
|
||||||
printf("%s\n", index(a, 'o'));
|
|
||||||
printf("%s\n", rindex(a, 'l'));
|
|
||||||
printf("%d\n", rindex(a, 'x') == NULL);
|
|
||||||
|
|
||||||
memset(&a[1], 'r', 4);
|
|
||||||
printf("%s\n", a);
|
|
||||||
|
|
||||||
memcpy(&a[2], a, 2);
|
|
||||||
printf("%s\n", a);
|
|
||||||
|
|
||||||
printf("%d\n", memcmp(a, "apple", 4) > 0);
|
|
||||||
printf("%d\n", memcmp(a, "grgr", 4) == 0);
|
|
||||||
printf("%d\n", memcmp(a, "zebra", 4) < 0);
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,19 +0,0 @@
|
|||||||
hello
|
|
||||||
gollo
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
5
|
|
||||||
gollo!
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
||||||
ollo!
|
|
||||||
lo!
|
|
||||||
1
|
|
||||||
grrrr!
|
|
||||||
grgrr!
|
|
||||||
1
|
|
||||||
1
|
|
||||||
1
|
|
@ -1,8 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
char a[10];
|
|
||||||
strcpy(a, "abcdef");
|
|
||||||
printf("%s\n", &a[1]);
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1 +0,0 @@
|
|||||||
bcdef
|
|
125
tests/30_hanoi.c
125
tests/30_hanoi.c
@ -1,125 +0,0 @@
|
|||||||
/* example from http://barnyard.syr.edu/quickies/hanoi.c */
|
|
||||||
|
|
||||||
/* hanoi.c: solves the tower of hanoi problem. (Programming exercise.) */
|
|
||||||
/* By Terry R. McConnell (12/2/97) */
|
|
||||||
/* Compile: cc -o hanoi hanoi.c */
|
|
||||||
|
|
||||||
/* This program does no error checking. But then, if it's right,
|
|
||||||
it's right ... right ? */
|
|
||||||
|
|
||||||
|
|
||||||
/* The original towers of hanoi problem seems to have been originally posed
|
|
||||||
by one M. Claus in 1883. There is a popular legend that goes along with
|
|
||||||
it that has been often repeated and paraphrased. It goes something like this:
|
|
||||||
In the great temple at Benares there are 3 golden spikes. On one of them,
|
|
||||||
God placed 64 disks increasing in size from bottom to top, at the beginning
|
|
||||||
of time. Since then, and to this day, the priest on duty constantly transfers
|
|
||||||
disks, one at a time, in such a way that no larger disk is ever put on top
|
|
||||||
of a smaller one. When the disks have been transferred entirely to another
|
|
||||||
spike the Universe will come to an end in a large thunderclap.
|
|
||||||
|
|
||||||
This paraphrases the original legend due to DeParville, La Nature, Paris 1884,
|
|
||||||
Part I, 285-286. For this and further information see: Mathematical
|
|
||||||
Recreations & Essays, W.W. Rouse Ball, MacMillan, NewYork, 11th Ed. 1967,
|
|
||||||
303-305.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#define TRUE 1
|
|
||||||
#define FALSE 0
|
|
||||||
|
|
||||||
#define N 4 /* This is the number of "disks" on tower A initially. */
|
|
||||||
/* Taken to be 64 in the legend. The number of moves
|
|
||||||
required, in general, is 2^N - 1. For N = 64, this is
|
|
||||||
18,446,744,073,709,551,615 */
|
|
||||||
|
|
||||||
int A[N], B[N], C[N]; /* These are the three towers. For example if the
|
|
||||||
state of A is 0,1,3,4, that means that there are three discs on A of sizes
|
|
||||||
1, 3, and 4. (Think of right as being the "down" direction.) */
|
|
||||||
|
|
||||||
void Hanoi(int,int*,int*,int*);
|
|
||||||
|
|
||||||
/* Print the current configuration of A, B, and C to the screen */
|
|
||||||
|
|
||||||
void
|
|
||||||
PrintAll()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
printf("A: ");
|
|
||||||
for(i=0;i<N;i++)printf(" %d ",A[i]);
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
printf("B: ");
|
|
||||||
for(i=0;i<N;i++)printf(" %d ",B[i]);
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
printf("C: ");
|
|
||||||
for(i=0;i<N;i++)printf(" %d ",C[i]);
|
|
||||||
printf("\n");
|
|
||||||
printf("------------------------------------------\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Move the leftmost nonzero element of source to dest, leave behind 0. */
|
|
||||||
/* Returns the value moved (not used.) */
|
|
||||||
|
|
||||||
int Move(int *source, int *dest)
|
|
||||||
{
|
|
||||||
int i,j;
|
|
||||||
|
|
||||||
while (i<N && (source[i])==0) i++;
|
|
||||||
while (j<N && (dest[j])==0) j++;
|
|
||||||
|
|
||||||
dest[j-1] = source[i];
|
|
||||||
source[i] = 0;
|
|
||||||
PrintAll(); /* Print configuration after each move. */
|
|
||||||
return dest[j-1];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Moves first n nonzero numbers from source to dest using the rules of Hanoi.
|
|
||||||
Calls itself recursively.
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
|
||||||
Hanoi(int n,int *source, int *dest, int *spare)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
if(n==1){
|
|
||||||
Move(source,dest);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Hanoi(n-1,source,spare,dest);
|
|
||||||
Move(source,dest);
|
|
||||||
Hanoi(n-1,spare,dest,source);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int
|
|
||||||
main()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* initialize the towers */
|
|
||||||
for(i=0;i<N;i++)A[i]=i+1;
|
|
||||||
for(i=0;i<N;i++)B[i]=0;
|
|
||||||
for(i=0;i<N;i++)C[i]=0;
|
|
||||||
|
|
||||||
printf("Solution of Tower of Hanoi Problem with %d Disks\n\n",N);
|
|
||||||
|
|
||||||
/* Print the starting state */
|
|
||||||
printf("Starting state:\n");
|
|
||||||
PrintAll();
|
|
||||||
printf("\n\nSubsequent states:\n\n");
|
|
||||||
|
|
||||||
/* Do it! Use A = Source, B = Destination, C = Spare */
|
|
||||||
Hanoi(N,A,B,C);
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
Solution of Tower of Hanoi Problem with 4 Disks
|
|
||||||
|
|
||||||
Starting state:
|
|
||||||
A: 1 2 3 4
|
|
||||||
B: 0 0 0 0
|
|
||||||
C: 0 0 0 0
|
|
||||||
------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
Subsequent states:
|
|
||||||
|
|
||||||
A: 0 2 3 4
|
|
||||||
B: 0 0 0 0
|
|
||||||
C: 0 0 0 1
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 3 4
|
|
||||||
B: 0 0 0 2
|
|
||||||
C: 0 0 0 1
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 3 4
|
|
||||||
B: 0 0 1 2
|
|
||||||
C: 0 0 0 0
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 0 4
|
|
||||||
B: 0 0 1 2
|
|
||||||
C: 0 0 0 3
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 1 4
|
|
||||||
B: 0 0 0 2
|
|
||||||
C: 0 0 0 3
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 1 4
|
|
||||||
B: 0 0 0 0
|
|
||||||
C: 0 0 2 3
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 0 4
|
|
||||||
B: 0 0 0 0
|
|
||||||
C: 0 1 2 3
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 0 0
|
|
||||||
B: 0 0 0 4
|
|
||||||
C: 0 1 2 3
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 0 0
|
|
||||||
B: 0 0 1 4
|
|
||||||
C: 0 0 2 3
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 0 2
|
|
||||||
B: 0 0 1 4
|
|
||||||
C: 0 0 0 3
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 1 2
|
|
||||||
B: 0 0 0 4
|
|
||||||
C: 0 0 0 3
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 1 2
|
|
||||||
B: 0 0 3 4
|
|
||||||
C: 0 0 0 0
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 0 2
|
|
||||||
B: 0 0 3 4
|
|
||||||
C: 0 0 0 1
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 0 0
|
|
||||||
B: 0 2 3 4
|
|
||||||
C: 0 0 0 1
|
|
||||||
------------------------------------------
|
|
||||||
A: 0 0 0 0
|
|
||||||
B: 1 2 3 4
|
|
||||||
C: 0 0 0 0
|
|
||||||
------------------------------------------
|
|
@ -1,12 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
int Count;
|
|
||||||
|
|
||||||
printf("hello world %d\n", argc);
|
|
||||||
for (Count = 0; Count < argc; Count++)
|
|
||||||
printf("arg %d: %s\n", Count, argv[Count]);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
hello world 5
|
|
||||||
arg 0: -
|
|
||||||
arg 1: arg1
|
|
||||||
arg 2: arg2
|
|
||||||
arg 3: arg3
|
|
||||||
arg 4: arg4
|
|
264
tests/32_led.c
264
tests/32_led.c
@ -1,264 +0,0 @@
|
|||||||
/* example from http://barnyard.syr.edu/quickies/led.c */
|
|
||||||
|
|
||||||
/* led.c: print out number as if on 7 line led display. I.e., write integer
|
|
||||||
given on command line like this:
|
|
||||||
_ _ _
|
|
||||||
| _| _| |_| |_
|
|
||||||
| |_ _| | _| etc.
|
|
||||||
|
|
||||||
We assume the terminal behaves like a classical teletype. So the top
|
|
||||||
lines of all digits have to be printed first, then the middle lines of
|
|
||||||
all digits, etc.
|
|
||||||
|
|
||||||
By Terry R. McConnell
|
|
||||||
|
|
||||||
compile: cc -o led led.c
|
|
||||||
|
|
||||||
If you just want to link in the subroutine print_led that does all the
|
|
||||||
work, compile with -DNO_MAIN, and declare the following in any source file
|
|
||||||
that uses the call:
|
|
||||||
|
|
||||||
extern void print_led(unsigned long x, char *buf);
|
|
||||||
|
|
||||||
Bug: you cannot call repeatedly to print more than one number to a line.
|
|
||||||
That would require curses or some other terminal API that allows moving the
|
|
||||||
cursor to a previous line.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#define MAX_DIGITS 32
|
|
||||||
#define NO_MAIN
|
|
||||||
|
|
||||||
|
|
||||||
/* Print the top line of the digit d into buffer.
|
|
||||||
Does not null terminate buffer. */
|
|
||||||
|
|
||||||
void topline(int d, char *p){
|
|
||||||
|
|
||||||
*p++ = ' ';
|
|
||||||
switch(d){
|
|
||||||
|
|
||||||
/* all these have _ on top line */
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 5:
|
|
||||||
case 7:
|
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
*p++ = '_';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*p++=' ';
|
|
||||||
|
|
||||||
}
|
|
||||||
*p++=' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print the middle line of the digit d into the buffer.
|
|
||||||
Does not null terminate. */
|
|
||||||
|
|
||||||
void midline(int d, char *p){
|
|
||||||
|
|
||||||
switch(d){
|
|
||||||
|
|
||||||
/* those that have leading | on middle line */
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
*p++='|';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*p++=' ';
|
|
||||||
}
|
|
||||||
switch(d){
|
|
||||||
|
|
||||||
/* those that have _ on middle line */
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
*p++='_';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*p++=' ';
|
|
||||||
|
|
||||||
}
|
|
||||||
switch(d){
|
|
||||||
|
|
||||||
/* those that have closing | on middle line */
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
case 1:
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 7:
|
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
*p++='|';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*p++=' ';
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Print the bottom line of the digit d. Does not null terminate. */
|
|
||||||
|
|
||||||
void botline(int d, char *p){
|
|
||||||
|
|
||||||
|
|
||||||
switch(d){
|
|
||||||
|
|
||||||
/* those that have leading | on bottom line */
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
case 2:
|
|
||||||
case 6:
|
|
||||||
case 8:
|
|
||||||
*p++='|';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*p++=' ';
|
|
||||||
}
|
|
||||||
switch(d){
|
|
||||||
|
|
||||||
/* those that have _ on bottom line */
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
case 2:
|
|
||||||
case 3:
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
case 8:
|
|
||||||
*p++='_';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*p++=' ';
|
|
||||||
|
|
||||||
}
|
|
||||||
switch(d){
|
|
||||||
|
|
||||||
/* those that have closing | on bottom line */
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
case 1:
|
|
||||||
case 3:
|
|
||||||
case 4:
|
|
||||||
case 5:
|
|
||||||
case 6:
|
|
||||||
case 7:
|
|
||||||
case 8:
|
|
||||||
case 9:
|
|
||||||
*p++='|';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
*p++=' ';
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Write the led representation of integer to string buffer. */
|
|
||||||
|
|
||||||
void print_led(unsigned long x, char *buf)
|
|
||||||
{
|
|
||||||
|
|
||||||
int i=0,n;
|
|
||||||
static int d[MAX_DIGITS];
|
|
||||||
|
|
||||||
|
|
||||||
/* extract digits from x */
|
|
||||||
|
|
||||||
n = ( x == 0L ? 1 : 0 ); /* 0 is a digit, hence a special case */
|
|
||||||
|
|
||||||
while(x){
|
|
||||||
d[n++] = (int)(x%10L);
|
|
||||||
if(n >= MAX_DIGITS)break;
|
|
||||||
x = x/10L;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* print top lines of all digits */
|
|
||||||
|
|
||||||
for(i=n-1;i>=0;i--){
|
|
||||||
topline(d[i],buf);
|
|
||||||
buf += 3;
|
|
||||||
*buf++=' ';
|
|
||||||
}
|
|
||||||
*buf++='\n'; /* move teletype to next line */
|
|
||||||
|
|
||||||
/* print middle lines of all digits */
|
|
||||||
|
|
||||||
for(i=n-1;i>=0;i--){
|
|
||||||
midline(d[i],buf);
|
|
||||||
buf += 3;
|
|
||||||
*buf++=' ';
|
|
||||||
}
|
|
||||||
*buf++='\n';
|
|
||||||
|
|
||||||
/* print bottom lines of all digits */
|
|
||||||
|
|
||||||
for(i=n-1;i>=0;i--){
|
|
||||||
botline(d[i],buf);
|
|
||||||
buf += 3;
|
|
||||||
*buf++=' ';
|
|
||||||
}
|
|
||||||
*buf++='\n';
|
|
||||||
*buf='\0';
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
char buf[5*MAX_DIGITS];
|
|
||||||
print_led(1234567, buf);
|
|
||||||
printf("%s\n",buf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef NO_MAIN
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
|
||||||
|
|
||||||
int i=0,n;
|
|
||||||
long x;
|
|
||||||
static int d[MAX_DIGITS];
|
|
||||||
char buf[5*MAX_DIGITS];
|
|
||||||
|
|
||||||
if(argc != 2){
|
|
||||||
fprintf(stderr,"led: usage: led integer\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* fetch argument from command line */
|
|
||||||
|
|
||||||
x = atol(argv[1]);
|
|
||||||
|
|
||||||
/* sanity check */
|
|
||||||
|
|
||||||
if(x<0){
|
|
||||||
fprintf(stderr,"led: %d must be non-negative\n",x);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
print_led(x,buf);
|
|
||||||
printf("%s\n",buf);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -1,4 +0,0 @@
|
|||||||
_ _ _ _
|
|
||||||
| _| _| |_| |_ |_ |
|
|
||||||
| |_ _| | _| |_| |
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int Count;
|
|
||||||
|
|
||||||
for (Count = 0; Count < 10; Count++)
|
|
||||||
{
|
|
||||||
printf("%d\n", (Count < 5) ? (Count*Count) : (Count * 3));
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,10 +0,0 @@
|
|||||||
0
|
|
||||||
1
|
|
||||||
4
|
|
||||||
9
|
|
||||||
16
|
|
||||||
15
|
|
||||||
18
|
|
||||||
21
|
|
||||||
24
|
|
||||||
27
|
|
@ -1,18 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a[4];
|
|
||||||
|
|
||||||
a[0] = 12;
|
|
||||||
a[1] = 23;
|
|
||||||
a[2] = 34;
|
|
||||||
a[3] = 45;
|
|
||||||
|
|
||||||
printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]);
|
|
||||||
|
|
||||||
int b[4];
|
|
||||||
|
|
||||||
b = a;
|
|
||||||
|
|
||||||
printf("%d %d %d %d\n", b[0], b[1], b[2], b[3]);
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,2 +0,0 @@
|
|||||||
12 23 34 45
|
|
||||||
12 23 34 45
|
|
@ -1,9 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
char a;
|
|
||||||
short b;
|
|
||||||
|
|
||||||
printf("%d %d\n", sizeof(char), sizeof(a));
|
|
||||||
printf("%d %d\n", sizeof(short), sizeof(b));
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,2 +0,0 @@
|
|||||||
1 1
|
|
||||||
2 2
|
|
@ -1,16 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int Count;
|
|
||||||
|
|
||||||
int Array[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753 };
|
|
||||||
|
|
||||||
for (Count = 0; Count < 10; Count++)
|
|
||||||
printf("%d: %d\n", Count, Array[Count]);
|
|
||||||
|
|
||||||
int Array2[10] = { 12, 34, 56, 78, 90, 123, 456, 789, 8642, 9753, };
|
|
||||||
|
|
||||||
for (Count = 0; Count < 10; Count++)
|
|
||||||
printf("%d: %d\n", Count, Array2[Count]);
|
|
||||||
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,20 +0,0 @@
|
|||||||
0: 12
|
|
||||||
1: 34
|
|
||||||
2: 56
|
|
||||||
3: 78
|
|
||||||
4: 90
|
|
||||||
5: 123
|
|
||||||
6: 456
|
|
||||||
7: 789
|
|
||||||
8: 8642
|
|
||||||
9: 9753
|
|
||||||
0: 12
|
|
||||||
1: 34
|
|
||||||
2: 56
|
|
||||||
3: 78
|
|
||||||
4: 90
|
|
||||||
5: 123
|
|
||||||
6: 456
|
|
||||||
7: 789
|
|
||||||
8: 8642
|
|
||||||
9: 9753
|
|
@ -1,12 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
char Buf[100];
|
|
||||||
int Count;
|
|
||||||
|
|
||||||
for (Count = 1; Count <= 20; Count++)
|
|
||||||
{
|
|
||||||
sprintf(Buf, "->%02d<-\n", Count);
|
|
||||||
printf("%s", Buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,20 +0,0 @@
|
|||||||
->01<-
|
|
||||||
->02<-
|
|
||||||
->03<-
|
|
||||||
->04<-
|
|
||||||
->05<-
|
|
||||||
->06<-
|
|
||||||
->07<-
|
|
||||||
->08<-
|
|
||||||
->09<-
|
|
||||||
->10<-
|
|
||||||
->11<-
|
|
||||||
->12<-
|
|
||||||
->13<-
|
|
||||||
->14<-
|
|
||||||
->15<-
|
|
||||||
->16<-
|
|
||||||
->17<-
|
|
||||||
->18<-
|
|
||||||
->19<-
|
|
||||||
->20<-
|
|
@ -1,29 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a[4][4];
|
|
||||||
int b = 0;
|
|
||||||
int x;
|
|
||||||
int y;
|
|
||||||
|
|
||||||
for (x = 0; x < 4; x++)
|
|
||||||
{
|
|
||||||
for (y = 0; y < 4; y++)
|
|
||||||
{
|
|
||||||
b++;
|
|
||||||
a[x][y] = b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (x = 0; x < 4; x++)
|
|
||||||
{
|
|
||||||
printf("x=%d: ", x);
|
|
||||||
for (y = 0; y < 4; y++)
|
|
||||||
{
|
|
||||||
printf("%d ", a[x][y]);
|
|
||||||
}
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,4 +0,0 @@
|
|||||||
x=0: 1 2 3 4
|
|
||||||
x=1: 5 6 7 8
|
|
||||||
x=2: 9 10 11 12
|
|
||||||
x=3: 13 14 15 16
|
|
@ -1,26 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
typedef int MyInt;
|
|
||||||
|
|
||||||
MyInt a = 1;
|
|
||||||
printf("%d\n", a);
|
|
||||||
|
|
||||||
struct FunStruct
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int j;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct FunStruct MyFunStruct;
|
|
||||||
|
|
||||||
MyFunStruct b;
|
|
||||||
b.i = 12;
|
|
||||||
b.j = 34;
|
|
||||||
printf("%d,%d\n", b.i, b.j);
|
|
||||||
|
|
||||||
typedef MyFunStruct *MoreFunThanEver;
|
|
||||||
|
|
||||||
MoreFunThanEver c = &b;
|
|
||||||
printf("%d,%d\n", c->i, c->j);
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,3 +0,0 @@
|
|||||||
1
|
|
||||||
12,34
|
|
||||||
12,34
|
|
@ -1,47 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
FILE *f = fopen("fred.txt", "w");
|
|
||||||
fwrite("hello\nhello\n", 1, 12, f);
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
char freddy[7];
|
|
||||||
f = fopen("fred.txt", "r");
|
|
||||||
if (fread(freddy, 1, 6, f) != 6)
|
|
||||||
printf("couldn't read fred.txt\n");
|
|
||||||
|
|
||||||
freddy[6] = '\0';
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
printf("%s", freddy);
|
|
||||||
|
|
||||||
char InChar;
|
|
||||||
char ShowChar;
|
|
||||||
f = fopen("fred.txt", "r");
|
|
||||||
while ( (InChar = fgetc(f)) != EOF)
|
|
||||||
{
|
|
||||||
ShowChar = InChar;
|
|
||||||
if (ShowChar < ' ')
|
|
||||||
ShowChar = '.';
|
|
||||||
|
|
||||||
printf("ch: %d '%c'\n", InChar, ShowChar);
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
f = fopen("fred.txt", "r");
|
|
||||||
while ( (InChar = getc(f)) != EOF)
|
|
||||||
{
|
|
||||||
ShowChar = InChar;
|
|
||||||
if (ShowChar < ' ')
|
|
||||||
ShowChar = '.';
|
|
||||||
|
|
||||||
printf("ch: %d '%c'\n", InChar, ShowChar);
|
|
||||||
}
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
f = fopen("fred.txt", "r");
|
|
||||||
while (fgets(freddy, sizeof(freddy), f) != NULL)
|
|
||||||
printf("x: %s", freddy);
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,27 +0,0 @@
|
|||||||
hello
|
|
||||||
ch: 104 'h'
|
|
||||||
ch: 101 'e'
|
|
||||||
ch: 108 'l'
|
|
||||||
ch: 108 'l'
|
|
||||||
ch: 111 'o'
|
|
||||||
ch: 10 '.'
|
|
||||||
ch: 104 'h'
|
|
||||||
ch: 101 'e'
|
|
||||||
ch: 108 'l'
|
|
||||||
ch: 108 'l'
|
|
||||||
ch: 111 'o'
|
|
||||||
ch: 10 '.'
|
|
||||||
ch: 104 'h'
|
|
||||||
ch: 101 'e'
|
|
||||||
ch: 108 'l'
|
|
||||||
ch: 108 'l'
|
|
||||||
ch: 111 'o'
|
|
||||||
ch: 10 '.'
|
|
||||||
ch: 104 'h'
|
|
||||||
ch: 101 'e'
|
|
||||||
ch: 108 'l'
|
|
||||||
ch: 108 'l'
|
|
||||||
ch: 111 'o'
|
|
||||||
ch: 10 '.'
|
|
||||||
x: hello
|
|
||||||
x: hello
|
|
@ -1,80 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
printf("#include test\n");
|
|
||||||
|
|
||||||
#if 1
|
|
||||||
#if 0
|
|
||||||
printf("a\n");
|
|
||||||
#else
|
|
||||||
printf("b\n");
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if 0
|
|
||||||
printf("c\n");
|
|
||||||
#else
|
|
||||||
printf("d\n");
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
#if 1
|
|
||||||
printf("e\n");
|
|
||||||
#else
|
|
||||||
printf("f\n");
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if 1
|
|
||||||
printf("g\n");
|
|
||||||
#else
|
|
||||||
printf("h\n");
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define DEF
|
|
||||||
|
|
||||||
#ifdef DEF
|
|
||||||
#ifdef DEF
|
|
||||||
printf("i\n");
|
|
||||||
#else
|
|
||||||
printf("j\n");
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#ifdef DEF
|
|
||||||
printf("k\n");
|
|
||||||
#else
|
|
||||||
printf("l\n");
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifndef DEF
|
|
||||||
#ifndef DEF
|
|
||||||
printf("m\n");
|
|
||||||
#else
|
|
||||||
printf("n\n");
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#ifndef DEF
|
|
||||||
printf("o\n");
|
|
||||||
#else
|
|
||||||
printf("p\n");
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ONE 1
|
|
||||||
#define ZERO 0
|
|
||||||
|
|
||||||
#if ONE
|
|
||||||
#if ZERO
|
|
||||||
printf("q\n");
|
|
||||||
#else
|
|
||||||
printf("r\n");
|
|
||||||
#endif
|
|
||||||
#else
|
|
||||||
#if ZERO
|
|
||||||
printf("s\n");
|
|
||||||
#else
|
|
||||||
printf("t\n");
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1,6 +0,0 @@
|
|||||||
#include test
|
|
||||||
b
|
|
||||||
g
|
|
||||||
i
|
|
||||||
p
|
|
||||||
r
|
|
@ -1,15 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int fred(int p)
|
|
||||||
{
|
|
||||||
printf("yo %d\n", p);
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
|
|
||||||
int (*f)(int) = &fred;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
printf("%d\n", (*f)(24));
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
void fred(void)
|
|
||||||
{
|
|
||||||
printf("yo\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
fred();
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1 +0,0 @@
|
|||||||
yo
|
|
@ -1,12 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int a;
|
|
||||||
|
|
||||||
for (a = 0; a < 2; a++)
|
|
||||||
{
|
|
||||||
int b = a;
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("it's all good\n");
|
|
||||||
|
|
||||||
void main() {}
|
|
@ -1 +0,0 @@
|
|||||||
it's all good
|
|
@ -1,16 +0,0 @@
|
|||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int Count = 0;
|
|
||||||
|
|
||||||
for (;;)
|
|
||||||
{
|
|
||||||
Count++;
|
|
||||||
printf("%d\n", Count);
|
|
||||||
if (Count >= 10)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user